Skip to main content

JSX in Depth: Expressions, Attributes and Fragments

Learn JSX in Depth: Expressions, Attributes and Fragments (Phase 2 · JSX and Components (Essential), ReactJS) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

JSX is JavaScript, not HTML • JSX looks like HTML but compiles to React.createElement / jsx() calls. A component returns one root element (use a fragment <>...</> to avoid an extra <div> ). • Put any JavaScript expression in { } : variables, function calls, ternaries, template literals. Statements ( if , for ) are not allowed inside braces. • Differences from HTML: className , htmlFor , camelCase attributes ( onClick , tabIndex ), self-close empty tags ( <img /> ), style takes an object.

More lessons in Phase 2 · JSX and Components (Essential)