Skip to main content

Command Palette

Search for a command to run...

"Mastering JSX: A Beginner's Guide to React's Secret Weapon"

Updated
2 min read
"Mastering JSX: A Beginner's Guide to React's Secret Weapon"
S

I’m an Incoming SDE Intern (.NET) focused on improving my skills in C#, JavaScript, and SQL. I share what I learn through simple explanations to help other beginners grow in their coding journey 🚀.

When you start learning React, the first thing you notice is something strange — writing HTML inside JavaScript. This is called JSX, and it’s one of the most important concepts in React. In this blog, we’ll understand what JSX is, why React uses it, and how it makes development easier.

📌 Watch the full JSX Explained video on YouTube:
👉 https://youtu.be/GJQHz2alcdo


What is JSX?

JSX stands for JavaScript XML.
It allows you to write HTML-like code directly inside JavaScript.

Example:

const element = <h1>Hello React!</h1>;

This looks like HTML, but it's actually JavaScript behind the scenes.


Why Does React Use JSX?

Here are the main reasons:

1. Easy to Read & Write

JSX makes your UI code easier to understand because structure and logic stay in one place.

2. Faster Development

You don’t need to use createElement() manually. JSX does that automatically.

3. Powerful with JavaScript

You can embed variables, functions, and expressions inside JSX using { }.

Example:

const name = "Sandip";
return <h2>Hello, {name}</h2>;

JSX is Not HTML

Even though JSX looks like HTML, there are some important differences:

🔸 Use className instead of class

<div className="container"></div>

🔸 Close all tags

<br /> 
<img />

🔸 Use one parent wrapper

JSX must return only one parent element.

return (
  <div>
    <h1>Hello</h1>
    <p>Welcome</p>
  </div>
);

Embedding JavaScript in JSX

You can use JavaScript inside { }.

Examples:

{10 + 20}             
{username}            
{isLoggedIn ? "Yes" : "No"}

JSX Behind the Scenes

JSX converts into React.createElement().

Example:

<h1>Hello</h1>

becomes:

React.createElement("h1", null, "Hello");

JSX is just syntax sugar that makes writing UI easier.


Benefits of JSX

⭐ Cleaner code
⭐ Easy to read
⭐ Extremely powerful with JavaScript
⭐ Helps build UI faster


Conclusion

JSX is the heart of React UI development. Once you understand JSX, building components becomes much easier, organised, and developer-friendly.

📌 If you want to learn JSX in depth, watch the video here:
👉 https://youtu.be/GJQHz2alcdo

Originally published on Medium.

More from this blog

React with Sandip

7 posts

React with Sandip is a beginner-friendly publication where I share React concepts in simple language, helping new developers learn from basics to advanced with examples and step-by-step guides.