DEV Community

Cover image for JSX — A Formal View (JavaScript + XML Syntax Extension)
QUDDUS
QUDDUS

Posted on

JSX — A Formal View (JavaScript + XML Syntax Extension)

JSX (JavaScript XML) is a syntax extension for JavaScript that allows developers to describe UI structures using a markup-like syntax embedded directly in JavaScript code.

At a conceptual level, JSX is not HTML and it is not executed by browsers directly. Instead, it acts as a declarative representation of a UI tree which is later transformed into standard JavaScript function calls during compilation.

Compilation Model

A JSX expression such as:


const element = <h1>Hello World</h1>;

is transformed by a compiler (e.g., Babel) into:


const element = React.createElement("h1", null, "Hello World");

or in modern React runtimes:

import { jsx } from "react/jsx-runtime";
const element = jsx("h1", { children: "Hello World" });
Enter fullscreen mode Exit fullscreen mode

Why it is called JavaScript + XML

The name originates from two characteristics:

  1. JavaScript Integration
  • JSX exists inside JavaScript.
  • Any JavaScript expression can be embedded using "{}".
   const name = "Quddus";
const element = <h1>Hello {name}</h1>;
Enter fullscreen mode Exit fullscreen mode
  1. XML-like Structure
  • JSX uses XML-style syntax rules such as:
  • Nested elements
  • Explicit closing tags
  • Attribute-based element configuration
   <div className="container">
  <h1>Title</h1>
   </div>
Enter fullscreen mode Exit fullscreen mode

Functional Role in React

From a theoretical perspective, JSX serves as a domain-specific language (DSL) for defining a virtual DOM tree.
During rendering, React interprets the resulting JavaScript objects to construct and reconcile the Virtual DOM, enabling efficient UI updates through a diffing algorithm.

So,

JSX can therefore be understood as:

  • A syntactic abstraction layer
  • A declarative UI description language
  • A compile-time transformation into JavaScript object structures that represent interface elements.

Top comments (0)