Curly Braces: The Escape Hatch to JavaScript
You'll learn: How to embed any JavaScript expression directly inside your JSX using curly braces.
The Core Idea
JSX looks like HTML, but you often need to inject dynamic values—variables, calculations, function calls—right into your markup. Curly braces {} are your escape hatch from JSX back into JavaScript land. Anywhere you place {expression} in JSX, React evaluates that JavaScript expression and uses its result.
Think of JSX as a template language, and curly braces as windows where you can "break out" to execute real JavaScript.
Where You Can Use Them
As attribute values:
<img src={userAvatar} alt={userName} />
As text content:
<h1>Welcome, {userName}!</h1>
<p>You have {messageCount} new messages.</p>
With expressions (not just variables):
<div>{2 + 2}</div> // Shows: 4
<span>{user.firstName.toUpperCase()}</span>
<p>{isLoggedIn ? 'Welcome back!' : 'Please sign in'}</p>
Why "Escape Hatch"?
The term emphasizes that JSX is the default mode—it's declarative markup. When you need to compute something or reference a variable, you "escape" into JavaScript's imperative world temporarily, then return to JSX. Without curly braces, userName would be treated as literal text, not a variable.
Key Takeaway: Curly braces {} let you embed any JavaScript expression inside JSX—they're the bridge between your static markup and dynamic data.