Skip to content
BENIBIX Learn

JavaScript XML (JSX)

Development🌐 Web DevelopmentFrameworks

Also known as JSX, TSX, React JSX

HTML-like tags written inside JavaScript. A build step turns them into code.

Think of it like

Think of it like a recipe card with pictures. It looks like the dish, but it is still a set of steps.

Example

Jack writes <h1>Hi {name}</h1> in a React file. When name is Emma, the page shows Hi Emma.

Why it matters

React and many other tools use it to describe what each part of the screen looks like. It keeps the look and the logic side by side.

Definition

JSX lets you write HTML-like tags inside JavaScript. React made it popular, and some other tools use it too. A build step turns each tag into a plain JavaScript call. Curly braces let you drop in JavaScript values, like {name}. Some names change, so class becomes className. In TypeScript files the same idea is called TSX.

Example code

jsx
function Greeting({ name }) {
  return <h1 className="title">Hi {name}</h1>;
}
A component that returns JSX. The curly braces hold a JavaScript value.
You write the tags on the left. A build step turns them into the calls in the middle.

Common mistake

Thinking JSX is HTML. It is JavaScript in disguise, so class is className and every tag must close.

Key takeaways

  1. 1
    Looks like HTML. But it lives inside JavaScript.
  2. 2
    Curly braces. They drop JavaScript values into the tags.
  3. 3
    Needs a build step. Browsers cannot read it as it is.

Compare