Understanding JSX in React

Zeeshan SafdarZeeshan Safdar
1 min read

When starting with React, many beginners get confused by JSX. But don't worry, I'm here to help you along the way!

๐Ÿ’ก What is JSX? JSX is a syntax that looks like HTML but allows us to write JavaScript expressions within curly braces {}. This means you can:

  • Reference variables

  • Loop over arrays (e.g., using map)

  • Use operators like the ternary ? :
    Note: Statements like if/else or for loops aren't allowed in JSX.

๐Ÿ”‘ Key JSX Rules:

  • JSX is a JavaScript expression, meaning you can store it in variables, use it in functions, and more.

It must have one root element. If you need multiple, use a React Fragment (<></>).

Please check the following Super helpful slide.

0
Subscribe to my newsletter

Read articles from Zeeshan Safdar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Zeeshan Safdar
Zeeshan Safdar

An accomplished front-end developer with a strong background in creating visually stunning and user-friendly websites and web applications. My deep understanding of web development principles and user-centered design allows me to deliver projects that exceed client expectations. I have a proven track record of success in delivering projects on time and to the highest standards, and I am able to work well in a team environment and am always looking for new challenges to take on.