LESSON 02 / 05

JSX

JSX looks like HTML inside JavaScript. Learn its rules: one parent, className, curly braces for values and self-closing tags.

๐ŸŽ“Mediumlevel
โฑ๏ธ30 minto finish
โœ๏ธ2activities

๐Ÿ“‚ Components & JSX๐Ÿท๏ธ React

๐ŸŽฏ By the end of this lesson you canโ€ฆ

  • Write valid JSX
  • Embed JavaScript values with { }
  • Use className, style objects and fragments
โš›๏ธ React App.jsx ๐Ÿ‘† Tap a line to explain it
1function App() {2  const name = "Asha";3  const today = new Date(2026, 8, 27);4  const score = 92;5  return (6    <>7      <h1 className="title">Hi {name}! ๐Ÿ‘‹</h1>8      <p>Today is {today.toDateString()}.</p>9      <p style={{ color: score >= 90 ? "green" : "orange", fontWeight: 700 }}>10        Score: {score} {score >= 90 && "๐ŸŒŸ"}11      </p>12      <img src="https://picsum.photos/seed/react/200/100" alt="Example" width="200" />13    </>14  );15}
HTML โ†’ JSX
HTMLJSX
class="card"className="card"
for="email"htmlFor="email"
style="color: red"style={{ color: "red" }}
<br><br />
onclick="โ€ฆ"onClick={โ€ฆ}
๐Ÿž Find the error
Why doesnโ€™t this compile?
1function App() {2  return (3    <h1>Title</h1>4    <p>Text</p>5  );6}
๐Ÿ› ๏ธ Business card

Make App return a card with an h2 showing the name variable, a paragraph with the job variable, and the city in a <small>, all inside a div with className="card".

๐Ÿ“Œ Key takeaways

  • Return one parent element (or a fragment <>โ€ฆ</>).
  • { } puts any JavaScript expression into JSX.
  • className not class; style={{ color: "red" }}; every tag must close (<img />).

Finished reading & practising?

Saved in this browser. Create a free account to keep it forever.