EasyReact Fundamentals📖 Theory Question

What is JSX and how does it work under the hood?

💡

Hint

JSX is syntactic sugar — Babel transforms it into React.createElement() calls

Full Answer

JSX is a syntax extension that looks like HTML inside JavaScript. It is NOT valid JS — it gets compiled by Babel into React.createElement() calls.

// What you write
const el = 

Hello {name}

; // What Babel compiles it to const el = React.createElement('h1', { className: 'title' }, 'Hello ', name); // React 17+ — new JSX transform (no need to import React) import { jsx as _jsx } from 'react/jsx-runtime'; const el = _jsx('h1', { className: 'title', children: ['Hello ', name] });

Key rules:

  • Single root element required (use <></> Fragment if needed)
  • Use className not class, htmlFor not for
  • Expressions in {} — not statements (if, for)
  • Self-close empty tags: <img />, <br />
  • camelCase for attributes: onClick, onChange
💡 JSX returns plain JS objects (React elements). They're just descriptions — cheap to create. React uses these to build and diff the Virtual DOM.

More React Fundamentals Questions

EasyWhat is React and what problem does it solve?EasyWhat is the Virtual DOM and how does reconciliation work?EasyWhat is the difference between a controlled and uncontrolled component?EasyWhat are props and how is prop drilling a problem?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint