Ad

Is JSX Just The HTML-like Markup Or The Surrounding Code As Well?

- 1 answer

I have a terminology question. Let's say I have the following code:

var Name = React.createClass({
  render: function() {
    var ranNum = Math.round(Math.random() * 200);

      return (
        <p>
          Hello, {ranNum}!
        </p>
      );
    }
});

When people talk about JSX, is it just the HTML-like items inside the return? Or does it also include the surrounding JavaScript like the ranNum declaration/initialization?

From reading the docs (and the proposed spec extension), JSX seems like it is just the HTML-like syntax. Everything else around it is just plain JavaScript.

Thanks,

Kirupa

Ad

Answer

From reading the docs (and the proposed spec extension), JSX seems like it is just the HTML-like syntax. Everything else around it is just plain JavaScript.

Yes. JSX is simply an extension of the JavaScript syntax. From the spec:

JSX is a XML-like syntax extension to ECMAScript without any definea XML-like syntax extension to ECMAScript without any defined semantics. It's NOT intended to be implemented by engines or browsers. It's NOT a proposal to incorporate JSX into the ECMAScript spec itself. It's intended to be used by various preprocessors (transpilers) to transform these tokens into standard ECMAScript.

Ad
source: stackoverflow.com
Ad