4 min read
•Question 2 of 48easyWhat is JSX?
Understanding JSX syntax in React.
What is JSX?
JSX (JavaScript XML) is a syntax extension for JavaScript that looks similar to HTML. It allows you to write HTML-like code in your JavaScript files.
How JSX Works
JSX is not valid JavaScript. It gets transformed by tools like Babel into regular JavaScript function calls.
JSX Rules
- Single Root Element: Must return one parent element
- Close All Tags: Even self-closing tags need
/> - camelCase Attributes: Use
classNameinstead ofclass - JavaScript in Curly Braces: Use
{}for JS expressions