JSX (JavaScript Syntax Extension and occasionally referred as JavaScript XML) is a React extension to the JavaScript language syntax which provides a way to structure component rendering using syntax familiar to many developers. It is similar in appearance to HTML.React components are typically written using JSX, although they do not have to be as components may also be written in pure JavaScript. JSX is similar to another extension syntax created by Meta (formerly Facebook) for PHP called XHP.
JSX allows us to write HTML elements in JavaScript and place them in the DOM without any createElement() and/or appendChild() methods. JSX converts HTML tags into react elements. You are not required to use JSX, but JSX makes it easier to write React applications.
HTML vs JSX
Hypertext Markup Language (HTML) is the standard language for documents that determine the structure of a web page.HTML is a very important language in web development. Your code is either in HTML originally or compiles to it so browsers can read it.JSX, on the other hand, means JavaScript Syntax Extension or JavaScript XML as some like to put it.
It was created as a syntactic sugar for React.createElement()
. It is an extension of JavaScript that allows developers to write HTML right within JavaScript. So when you're writing JSX, technically you're writing JavaScript and HTML together.
Also, that means JavaScript's reserved keywords must be kept intact. And that is why the “for” attribute in HTML is “HTMLFor” in JSX, since "for" is one of the commonest JavaScript reserved keywords.
In terms of support by browsers, HTML is supported by all of them. JSX, on the other hand, was never really intended to be, so you need a compiler like Babel or Webpack to transpile JSX into the JavaScript that browsers understand.