React Expressions are one of the core features that make JSX powerful. They allow you to embed dynamic values, logic, and JavaScript computations directly inside your UI markup.
Whenever you see something inside { curly braces } in JSX, that’s a React Expression.
A React Expression is any valid JavaScript expression written inside curly braces {} within JSX.
It tells React:
“Evaluate this JavaScript and insert the result right here in the UI.”
Example:
const name = "Luke";
function App() {
return <h1>Hello, {name}!</h1>;
}
React evaluates {name} and renders:
Hello, Luke!
React allows any JavaScript expression, meaning anything that returns a value.
if, for, switch)React Expressions require expressions, not full statements.
const age = 25;
return <p>I am {age} years old.</p>;
return <p>2 + 5 = {2 + 5}</p>;
function greet() {
return "Welcome to React!";
}
return <h2>{greet()}</h2>;
React doesn’t allow if statements directly in JSX, but you can use ternary expressions.
const isLoggedIn = true;
return (
<div>
{isLoggedIn ? <p>Dashboard</p> : <p>Please Log In</p>}
</div>
);
Great for rendering elements only when a condition is true.
const show = true;
return <div>{show && <p>This is visible</p>}</div>;
If show is false → nothing renders.
const first = "React";
const second = "Expressions";
return <h3>{`${first} ${second}`}</h3>;
Arrays render each item in order (best used for lists with .map()).
const items = ["HTML", "CSS", "JS"];
return <div>{items}</div>;
Output:
HTMLCSSJS
(It prints them without commas unless you format them.)
This is one of the most powerful uses of React expressions:
const languages = ["JavaScript", "TypeScript", "Python"];
return (
<ul>
{languages.map((lang, i) => (
<li key={i}>{lang}</li>
))}
</ul>
);
You cannot display an object directly:
return <p>{user}</p>; // ❌ Error
But you can access its properties:
const user = { name: "Luke", role: "Developer" };
return <p>{user.name} — {user.role}</p>;
JSX is just an expression too!
const message = <strong>React is awesome!</strong>;
return <p>{message}</p>;
You can even use them inside attributes:
const imageUrl = "/avatar.png";
return <img src={imageUrl} alt="Profile" />;
If an expression evaluates to undefined, nothing shows.
const data = undefined;
return <p>{data}</p>; // Renders nothing — no error
Useful for hiding optional values “automatically.”
{if (isAdmin) { <p>Admin</p> }} // Wrong
{isAdmin ? <p>Admin</p> : null}
They allow React to:
They are at the heart of React’s declarative nature.
function Profile({ user }) {
return (
<div>
<h1>{user.name}</h1>
<p>Status: {user.online ? "Online" : "Offline"}</p>
{user.online && <span className="green-dot"></span>}
<h3>Skills</h3>
<ul>
{user.skills.map((skill) => (
<li key={skill}>{skill}</li>
))}
</ul>
</div>
);
}
This demonstrates conditional renders, mappings, and value interpolation—all using React Expressions.
React Expressions let you embed dynamic JavaScript logic inside JSX using {} so your UI updates automatically based on values, functions, and conditions.
Latest tech news and coding tips.
Visual Studio Code (VS Code) is powerful out of the box, but its real strength…
1. What Is a Variable in JavaScript? A variable is a named container used to store data…
1. What Is a Queue? A Queue is a linear data structure that follows the principle: FIFO – First…
Angular is a full-featured frontend framework built by Google for creating large, maintainable, and high-performance web applications.…
What Is Responsive Web Design? Responsive Web Design (RWD) is an approach to building websites…
The Geolocation API allows a web application to access a user’s geographical location (latitude, longitude, and more), with…