Introduction
JSX lets you write HTML-like code inside JavaScript. It makes building user interfaces easier and clearer.
JSX lets you write HTML-like code inside JavaScript. It makes building user interfaces easier and clearer.
const element = <tagName>Content</tagName>;const greeting = <h1>Hello, world!</h1>;const name = 'Alice'; const greeting = <h1>Hello, {name}!</h1>;
const list = <ul> <li>Item 1</li> <li>Item 2</li> </ul>;
This React component uses JSX to show a welcome message with a user's name.
import React from 'react'; function Welcome() { const user = 'Friend'; return <h1>Welcome, {user}!</h1>; } export default Welcome;
Browsers do not understand JSX directly; React transforms it into JavaScript before running.
Always use a single parent element in JSX or wrap multiple elements in a fragment.
JSX lets you write HTML-like code inside JavaScript for React.
It makes UI code easier to read and write.
You can mix JavaScript expressions inside JSX using curly braces.
const element = <h1>Hello, {"React"} & JSX!</h1>;
ReactDOM.render(element, document.getElementById('root'));const element = <div>Hello {name}</div>
ReactDOM.render(element, document.getElementById('root'));
Assuming name is not defined anywhere.The sum is {2 + 3}
correctly uses curly braces with 2 + 3, which evaluates to 5. Options A and B treat it as a string, and C uses parentheses without curly braces, so it won't evaluate.Pass the test and this pattern moves unknown