liveBook · Manning

JSX

As explained in Acing the Frontend Interview

JSX is a JavaScript syntax extension that represents UI elements with XML-like markup.

JSX (JavaScript XML) is HTML-like syntax written within JavaScript or TypeScript to describe React UI elements. It makes component structure readable while supporting React’s declarative approach: describe the UI for the current state, then let React handle DOM updates. section 1.4 section 4.1

Interview question: What does JSX contribute?

Given `const App = (<div><h1>Hello</h1><p>World</p></div>);`, explain that the markup expresses a nested element structure. Its corresponding element representation has a `div` type and children with `h1` and `p` types. If asked about performance, distinguish the readable JSX description from React’s Virtual DOM and reconciliation, which handle updates. section 4.1

For a follow-up, demonstrate how JSX expresses changing UI:

  • Use expressions and loops, such as `<ul>{items.map(item => <li>{item}</li>)}</ul>`, to describe a list rather than append each DOM node manually. section 4.1
  • Recognize conditions, fragments, and portals as further JSX topics; do not confuse those patterns with React’s update mechanism. section 4.1
Table 4.2 Comparison of declarative vs. imperative UI
Aspect
Declarative (React)
Imperative (Vanilla JS)
Approach
Describes what the UI should look like based on state; React handles rendering and updates automatically.
Specifies step-by-step DOM updates and manual state tracking.
Code Example
<ul>
  {items.map(item =>    
    <li>{item}</li>)}
</ul>
const li = document.createElement('li');
ul.appendChild(li);
Efficiency
Virtual DOM diffing minimizes unnecessary updates for better performance.
Manual DOM updates are prone to errors and inefficiencies.
Maintainability
Component encapsulation makes changes localized and predictable.
Tightly coupled code increases complexity and fragility.
Testability
Components are easily testable in isolation with Jest or React Testing Library.
Requires complex mocking of DOM APIs for unit testing.

Compare the JSX list with `document.createElement()` and `appendChild()` to articulate declarative versus manual DOM updates. section 4.1

How Acing the Frontend Interview covers it

How deep it goes
Moves from HTML-like markup to expressions, loops, and conditions, while naming fragments and portals without detailing their implementation.
Examples
Contrasts a mapped JSX list with manual DOM creation and pairs nested markup with its element-object representation.
What it assumes
Assumes core web technologies and React fundamentals rather than teaching React from scratch.
What you can do after
Apply it via React to describe UI elements and distinguish JSX’s readability from React’s DOM-update process.
How it connects
Connects JSX to declarative UI, component-based architecture, the Virtual DOM, and reconciliation.

Also explained in

Compare how 9 books explain JSX →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Frontend Interview. The section links point to the parts of the book it draws on.