How to use JavaScript in React JSX with curly braces

💡 A small React learning moment I wanted to share! While working on a simple React component recently, I ran into an issue — I wanted to display a variable’s value inside my JSX, but nothing was showing up. I kept trying different things until I realized… I wasn’t actually calling JavaScript correctly inside JSX! 😅 Here’s what I was missing: function Greeting() { const name = "Divya"; return <h2>Hello {name}</h2>; // ✅ Use curly braces to run JS in JSX } I had forgotten the curly braces {} — that’s how React lets us run JavaScript expressions inside JSX! It only accepts expressions (something that returns a value), not full statements like loops or if-else. That tiny fix made my component work perfectly and helped me understand how React blends JS logic with UI. Every bug teaches something new — this one taught me how powerful and elegant JSX really is! 💪 #ReactJS #JavaScript #LearningByDoing #WebDevelopment #MERNStack #CodingJourney

😂😂 We learn from silly mistakes all the time😂🤝🏻

Like
Reply

To view or add a comment, sign in

Explore content categories