Skip to content

Expression

In one line

An expression is any piece of code that evaluates to a single value, like 2 + 3 or x * 10.

In simple words

An expression is a combination of values, variables, and operators that the computer evaluates to produce a single result. 2 + 3 is an expression that evaluates to 5. name + "!" is an expression that evaluates to a string.

Expressions can be simple (a single value like 42 or "hello") or complex (nested operations like (a + b) * c / 2). They can appear anywhere a value is expected: in assignments, function arguments, conditions, and return statements.

The key distinction is: an expression PRODUCES a value; a statement DOES something. let x = 5 is a statement (it declares a variable). 5 is an expression (it evaluates to 5). x + 1 is an expression (it evaluates to 6 if x is 5).

Example

javascript
let x = 5;

// These are all expressions:
console.log(42);          // 42
console.log(x + 3);       // 8
console.log(x > 0);       // true
console.log("Hi, " + "Ada"); // "Hi, Ada"

Each argument to console.log is an expression that evaluates to a value before being printed.

Common confusions

  • Confused with: statement

    The difference: An expression evaluates to a value (2 + 3 → 5); a statement performs an action (let x = 5;). Some constructs are both: x++ is both an expression and a statement.

Related terms

Related Resources

Related Lessons

  • Variables

    Expressions use variables and operators.

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary