Numbers and Strings: Rendered as Text
What you'll learn: How React automatically converts numbers and strings into visible text when you use them in JSX.
The Core Idea
When you put a number or string inside curly braces in JSX, React simply displays it as text on the page. There's no special handling—what you write is what you see.
function App() {
const age = 25;
const name = "Sarah";
return (
<div>
<p>Name: {name}</p>
<p>Age: {age}</p>
<p>Calculation: {10 + 5}</p>
</div>
);
}
This renders exactly as you'd expect:
- Name: Sarah
- Age: 25
- Calculation: 15
Why This Matters
Unlike null, undefined, true, and false (which render as nothing), numbers and strings are primitive values that React knows how to display. They get converted into text nodes in the DOM automatically.
Think of React as a helpful assistant: when you hand it a number like 42 or a string like "Hello", it knows you want those shown to the user, so it turns them into visible text without you needing to do anything extra.
function PriceTag() {
const price = 29.99;
const currency = "USD";
return <div>Price: {price} {currency}</div>;
}
// Renders: Price: 29.99 USD
Key Takeaway: Numbers and strings inside JSX curly braces are automatically rendered as text content in the DOM—no conversion function needed, they just work.