JavaScript Expressions & Statements

Home » JavaScript Tutorial » JavaScript Introduction » 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.

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 (...) { ... }.

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().
FeatureExpression (Produces a Value)Statement (Performs an Action)
Primary GoalProduces a single value.Performs an action or command.
Example Code42const answer = 42;
Arithmetic10 * (3 + 7)// N/A (Arithmetic is an Expression)
Declaration/Control// N/A (Declaration is a Statement)if (isAdult) { ... }
Function UseMath.max(10, 20)function greet() { … }

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.
JavaScript

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)
JavaScript

Remember: you use expressions (ingredients/values) within the structure of statements (the instructions/recipe steps) to make your program run.