🔤 What is JSX?
JSX (JavaScript XML) is a syntax extension for JavaScript that allows you to write HTML-like code directly inside your JavaScript files. It is used with React to describe what the UI should look like.
💡 Why Use JSX?
- JSX makes it easier to write and understand UI logic visually.
- Combines HTML structure and JavaScript logic in one place.
- Helps React compile the UI into efficient JavaScript code using Babel.
📘 Basic JSX Example
const element = <h1>Hello, JSX!</h1>;
ReactDOM.render(element, document.getElementById('root'));
The JSX <h1>Hello, JSX!</h1> is compiled to:
React.createElement('h1', null, 'Hello, JSX!');
🔀 Embedding Expressions in JSX
You can embed any JavaScript expression inside curly braces:
const name = "React";
const element = <h1>Welcome to {name}</h1>;
📏 JSX Rules
- Wrap multiple elements in a single parent (like
<div>or<>). - Use
classNameinstead ofclass. - Use
camelCasefor attribute names (e.g.,onClick,tabIndex). - Always close tags (self-closing like
<img />).
⚙️ JSX Requires a Compiler
Browsers don’t understand JSX directly. It must be compiled to regular JavaScript using a tool like Babel, which is automatically included in tools like Create React App.


