JSX (JavaScript)

JSX (JavaScript XML, formally JavaScript Syntax eXtension) is an XML-like extension to the JavaScript language syntax. Initially created by Facebook for use with React, JSX has been adopted by multiple web frameworks. Being a syntactic sugar, JSX is generally transpiled into nested JavaScript function calls structurally similar to the original JSX.

Markup
An example of JSX code:

Nested elements
Multiple elements on the same level need to be wrapped in a single React element such as the  element shown above, a fragment delineated by   or in its shorthand form , or returned as an array.

Attributes
JSX provides a range of element attributes designed to mirror those provided by HTML. Custom attributes can also be passed to the component. All attributes will be received by the component as props.

JavaScript expressions
JavaScript expressions (but not statements) can be used inside JSX with curly brackets :

The example above will render:

Conditional expressions
If–else statements cannot be used inside JSX but conditional expressions can be used instead. The example below will render { i === 1 ? 'true' : 'false' } as the string  because   is equal to 1. The above will render:

Functions and JSX can be used in conditionals:

The above will render:

Code written in JSX requires conversion with a tool such as Babel before it can be understood by web browsers. This processing is generally performed during a software build process before the application is deployed.