React · Frontend system thinking
What is JSX and how does it work?
Short answer
JSX is syntax sugar for creating React elements. It looks like HTML inside JavaScript and compiles to function calls such as jsx(type, props, children).
Browsers do not understand JSX. A compiler such as Babel or the TypeScript JSX transform converts it into JavaScript before the browser runs it. Modern React uses the automatic JSX runtime, so you do not need to import React just to use JSX.
const element = <h1 className="title">Hello</h1>;
// Compiles to something like:
const element = jsx("h1", {
className: "title",
children: "Hello",
});What you can embed
- JavaScript expressions inside curly braces, such as
{user.name} - Conditional expressions and array mappings
- Components as capitalized tags, such as
<UserCard /> - Fragments to return multiple elements without an extra DOM node
function UserList({ users }) {
return (
<>
{users.map((user) => (
<UserCard key={user.id} user={user} />
))}
</>
);
}JSX is not HTML. Attributes use camelCase, class becomes className, and event handlers receive functions rather than strings. JSX also escapes interpolated text by default, which helps prevent injection.
dangerouslySetInnerHTML bypasses escaping. Only use it with sanitised HTML from a trusted source.Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1How is JSX different from HTML?
- 2What does JSX compile to?
- 3Why do components need capitalised names?
- 4Is JSX safe from XSS?
Say it in the interview
JSX is syntax sugar for creating React elements. It looks like HTML inside JavaScript, but a compiler turns it into function calls. I can embed expressions in curly braces, use fragments to avoid extra DOM nodes, and map arrays into components. JSX is not HTML: attributes are camelCase, events take functions, and interpolated text is escaped by default.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live React mock interview and get scored feedback on depth, clarity and confidence.