JavaScript Expressions & Statements
Every line of code you write in JavaScript is categorized as either a Statement (an action) or an Expression (a value). Understanding the difference is foundational to reading and writing predictable code.
The easiest way to think about the distinction is this: If a piece of code produces a single value, it’s an Expression. If it performs an action, it’s a Statement.
Statements (Performs an Action)
A Statement is a complete unit of execution that commands the computer to perform an action. Statements typically end with a semi-colon (;).
A statement’s main purpose is to perform an action or control the flow of the program; it does not necessarily produce a value that you can use elsewhere but typically will have places for expressions to be added to produce a value.
Key Characteristics of Statements:
- Action-Oriented: Declaring a variable, controlling a loop, or defining a function.
- Examples:
const x = 5;,if (condition) { ... },for (...) { ... }.
Expressions (Produces a Single Value)
An Expression is any piece of code that resolves to (or evaluates to) a single, concrete value.
If you can place the code on the right side of an assignment operator (=), it is an Expression, because the right side must produce a value for the left side to store.
Key Characteristics of Expressions:
- Value-Oriented: A number, a string, a calculation, or a function call that returns a result.
- Examples:
10 + 5,"Hello",age > 18,myFunction().
Expressions VS. Statements
| Feature | Expression (Produces a Value) | Statement (Performs an Action) |
| Primary Goal | Produces a single value. | Performs an action or command. |
| Example Code | 42 | const answer = 42; |
| Arithmetic | 10 * (3 + 7) | // N/A (Arithmetic is an Expression) |
| Declaration/Control | // N/A (Declaration is a Statement) | if (isAdult) { ... } |
| Function Use | Math.max(10, 20) | function greet() { … } |
The Overlap: Expression Statements
In JavaScript, most of the code you write will be an Expression Statement. An expression statement is a statement that consists of an expression followed by a semicolon. Essentially, any valid expression can be turned into a statement by adding a semicolon at the end. This allows the side effects of an expression, such as variable assignment or function execution, to be performed as part of the program’s flow.
// Expression Statement Examples:
const total = 5 + 5; // The expression '5 + 5' is assigned to 'total'.
console.log("Expression Statement"); // console.log is an Expression producing a value.
// The semi-colon at the end turns the whole line into a Statement.JavaScriptTesting for Expressions VS. Statements in the Console
In the console you can check on whether or not a lin of JavaScript is an expression or statement by seeing if the console returns the expected value (an expression) or the undefined primitive data-type (statement).
// Checking Expressions VS. Statements in the console
let x = 22 // Statement
undefined // (statement confirmed)
x // Expression (since it evaluates to the value 22)
22 // (expression confirmed)JavaScriptRemember: you use expressions (ingredients/values) within the structure of statements (the instructions/recipe steps) to make your program run.




