DEV Community

Swetha
Swetha

Posted on

.js vs .jsx

The .js file is a file that contains standard JavaScript code. These files do not contain the UI related code and are used for writing the logics and the functions.

Used for regular JavaScript code and logic.
Does not include JSX (HTML-like syntax).
Can be used for utility functions, state management, or simple React components.
No extra tools needed to run.

.jsx

JSX (JavaScript XML) is an extension of JavaScript that lets developers write HTML-like code inside JavaScript. Files with the .jsx extension usually contain components written in JSX, which React then converts into JavaScript function calls.

Used for React components with JSX (HTML-like syntax)
Includes JSX to define the UI structure.
Mainly for creating and rendering the user interface.
Requires tools like Babel to convert JSX into JavaScript.

Image description

Babel

Babel works through a series of transformations that take your modern JavaScript (including JSX) and convert it into backwards-compatible JavaScript.
Babel is often referred to as a transpiler (A transpiler (short for source-to-source compiler) is a tool that converts code from one version of a language to another, often for compatibility reasons.) rather than a compiler because its primary function is to translate one version of JavaScript into another version of JavaScript.

Transpiling usually refers to the process of translating source code from one version of a language to another version of the same language (e.g., from ES6 to ES5, or JSX to JavaScript).

Reference Link

https://www.geeksforgeeks.org/reactjs/what-is-the-difference-between-a-js-and-jsx-file-in-react/
https://www.geeksforgeeks.org/reactjs/reactjs-babel-introduction/

Top comments (0)