Expression vs Statement
Understanding the difference between expressions and statements is one of those things that clicks once and changes how you read code.
- Expression — produces a value.
5 + 3,"hello",fn() - Statement — performs an action.
if (...),for (...),let x = ...
An expression can be used anywhere a value is expected. A statement cannot — you can't pass an if to a function.
// Expression: produces a value
5 + 3
"hello".toUpperCase()
Math.max(10, 20)
// Statement: performs an action
let result = 5 + 3;
if (result > 5) {
console.log("Bigger than 5");
}
// Function expression (expression used where a statement might go)
const add = function(a, b) {
return a + b;
};
console.log(add(2, 3));
Try it Yourself →