What is the difference between JS and JSX?
https://www.skillgain.in/

What is the difference between JS and JSX?

What is the difference between JS and JSX?

JavaScript

How are JS and JSX different from one another?

JavaScript is a programming language that adheres to ECMAScript that enables developers to add more interactivity to their web pages. JavaScript is used behind the scenes each time a webpage loads, a slideshow plays, or an animated image is displayed. In essence, it gives a website more life and originality, which makes it more interesting.

React is an open source frontend JavaScript toolkit that enables programmers to build sophisticated user interfaces from smaller components. JSX is simply a syntax extension for JavaScript that enables users to write React components.

In JavaScript or JSX By combining HTML and JavaScript, XML makes code simpler for users to read and comprehend. JSX integrates interaction


How are JS and JSX different?

Both JS and JSX are interchangeable, however there are differences in how functionality is distributed throughout the application and how the user interface is built.

To write JS, first create a straightforward HTML document, then write the JS within the script element like follows:

<div>

<h1>Fruit List</h1>

<ul id="fruit-list">

<li>Orange</li>

<li>Mango</li>

<li>Pear</li>

</ul>

</div>

After that, JavaScript is included to add the functionality:

<script>

function addItemToList() {

// Add item

}

</script>

But the similar code of JSX in React starts with a fixed HTML file:

<div id="root"></div>

And then the code is written which looks similar to HTML, but is JSX:

export function FruitList(props) {

return (

<div>

<h1>Fruit List</h1>

<ul>

<li>Mango</li>

<li>Pear</li>

<li>Guava</li>

</ul>

</div>

)

};

The functionality is also divided up into components in this manner, which makes complex applications simpler to comprehend.

React may be developed with both JS and JSX, therefore JSX is not required, but because it is comparable to HTML, JSX makes it simpler for users to create React apps. It makes HTML code easier to write and maintain, which makes handling functionality simpler.

JS is simply a scripting language, adding functionality into your website. JSX is an addition to the JavaScript syntax which is a mixture of both HTML and JavaScript. Both JS and JSX are interchangeable but JSX makes the code easier to understand for users. JSX is popularly used in React, as it makes the job of building an application much easier.

Charles Robertson

Technical Developer @ Establish Mindfulness Ltd, with expertise in Angular & Coldfusion

1mo

You can use the JSX code example, in a .js file? Now I realize that you may not have implied the opposite view, but I just thought I would add this point, to clarify this issue, for developers, new to React. Here is an example: post.js class Post extends Component { constructor(props) { super(props); } componentDidMount() { … } render() { … return ( <Card> <CardTitle> … </CardTitle> <CardText> … </CardText> <CardActions border> … </CardActions> <CardMenu style={{color: '#fff'}}> … </CardMenu> </Card> ); } } export default Post; Here is a link that describes this exact conundrum: https://stackoverflow.com/questions/47661192/using-js-file-extensions-whilst-writing-scripts-that-return-jsx As you can see from my code example, the ability to write JSX inside .js files, has been available, as far back as class components. This is certainly not a new React feature. 🙏

Shubham Kumar

Front-End Developer | Learning Backend | Write techie stuffs

6mo

a user can write javascript logic by using {} tags, it is not necessary to write in <script> tags. Then why it is preferred to choose jsx over js, i cannot see any difference, if there is difference, please elaborate, It is very confusing for me.....

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics