/ˈdʒeɪ-ɛs-ɛks/

n. “Write HTML inside JavaScript, without the browser complaining.”

JSX, short for JavaScript XML, is a syntax extension for JavaScript commonly used with React. It allows developers to write HTML-like markup directly within JavaScript code, which is then transformed into standard JavaScript calls by a compiler like Babel. This makes building UI components more intuitive and declarative.

Key aspects of JSX include:

  • Declarative Syntax: HTML-like tags describe the UI structure, making code easier to read and maintain.
  • Embedded Expressions: JavaScript expressions can be included within curly braces { } for dynamic content.
  • Component Integration: JSX works seamlessly with React components, allowing hierarchical UI composition.

Here’s a simple example using JSX in a React component:

import React from 'react';

function Greeting({ name }) {
return <h1>Hello, {name}!</h1>;
}

export default function App() {
return <Greeting name="Alice" />;
}

In this snippet, the Greeting component uses JSX to embed the name prop directly into the HTML-like output. React compiles this into JavaScript calls that create and update the DOM efficiently.

In essence, JSX blends the readability of HTML with the full power of JavaScript, simplifying the creation and management of dynamic user interfaces.