Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does JSX stand for?

What does JSX stand for?

I am referring to the JSX that is defined as a XML-like syntax extension to ECMAScript, which has become quite popular with the increasing popularity of ReactJS.

like image 993
user2977636 Avatar asked Sep 13 '16 03:09

user2977636


People also ask

What is React vs JSX?

JSX is just a syntax extension of JavaScript which allows users to write React components; React is an open source frontend JavaScript library for building complex UIs; it allows the programmers to create complex UIs from smaller components.

What is JSX and how it works?

JSX stands for JavaScript syntax extension. It is a JavaScript extension that allows us to describe React's object tree using a syntax that resembles that of an HTML template. It is just an XML-like extension that allows us to write JavaScript that looks like markup and have it returned from a component.

Why JSX is used in React?

React doesn't require using JSX, but most people find it helpful as a visual aid when working with UI inside the JavaScript code. It also allows React to show more useful error and warning messages.

What JSX called?

JSX: JavaScript XML These snippets of suspiciously-HTML-like code are not HTML, but a syntax extension to JavaScript based on ES6 called “JavaScript XML.” More commonly referred to as “JSX,” JavaScript XML is a form of markup that allows us to write HTML in React by converting HTML tags into React elements.


1 Answers

JSX stands for JavaScript XML. With React, it's an extension for XML-like code for elements and components. Per the React docs and as you mentioned:

JSX is a XML-like syntax extension to ECMAScript without any defined semantics

From the quote above, you can see that JSX doesn't have defined semantics, it's just an extension to JavaScript that allows to write XML-like code for simplicity and elegance, and then you transpile the JSX into pure JavaScript function calls with React.createElement. Per the React tutorial:

JSX is a preprocessor step that adds XML syntax to JavaScript. You can definitely use React without JSX but JSX makes React a lot more elegant.

Just like XML, JSX tags have a tag name, attributes, and children. If an attribute value is enclosed in quotes, the value is a string. Otherwise, wrap the value in braces and the value is the enclosed JavaScript expression.

Any code in JSX is transformed into plain JavaScript/ECMAScript. Consider a component called Login. Now we render it like so with JSX:

<Login foo={...} bar={...} /> 

As you can see, JSX just allows you to have XML-like syntax for tags, representing components and elements in React. It's transpiled into pure JavaScript:

React.createElement(Login, { foo: ..., bar: ... }); 

You can read more at the docs.

like image 137
Andrew Li Avatar answered Sep 24 '22 20:09

Andrew Li