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








