๐ฏ 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 |
|---|---|
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.classNamenotclass;style={{ color: "red" }}; every tag must close (<img />).
Finished reading & practising?
Saved in this browser. Create a free account to keep it forever.