What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A JavaScript expression is a valid unit of code that resolves to a value. Expressions can be as small as 3 + 4 or as involved as a function call; some also change program state while producing their value. Understanding expressions makes it easier to read operators, conditions, assignments, and the difference between statements and values.

What is a JavaScript expression?

An expression is code JavaScript evaluates to produce a value. For example, 3 + 4 evaluates to 7, and user.name evaluates to the value of the name property on user. Expressions can appear wherever JavaScript expects a value, including a variable initializer, a condition, a function argument, or a return value. MDN describes expressions and operators.

Not every expression is a calculation, and not every expression is free of side effects. The expression x = 7 assigns 7 to x and also evaluates to 7. A function call might return a value and also log a message, update an object, or perform another action. By contrast, 3 + 4 simply produces a value without changing program state.

How expressions differ from statements and declarations

Expressions provide values; statements organize execution and control flow. A declaration such as const total = 3 + 4; creates a binding, and the expression 3 + 4 supplies its initial value. Likewise, if (total > 5) uses an expression as its condition, and return total uses one as the function’s return value.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An expression statement is an expression used in a position where JavaScript expects a statement. JavaScript evaluates it, but the resulting value is discarded. Standalone assignments, function calls, and increments are common because their effects matter even when their values are unused:

saveRecord(record); // Calls a function
count++;            // Changes count
status = "ready";   // Assigns a value

A bare expression such as 3 + 4; is legal in many statement positions, but it does not save or display 7. If the expression has no side effect and its value is not used, it usually does not accomplish anything.

JavaScript’s grammar can make the start of an expression statement ambiguous. At the beginning of a statement, { name: "Ada" } is parsed as a block containing a label, not as an object literal expression. Parentheses clarify the intent: ({ name: "Ada" }). The language specification defines the grammar for expressions and expression statements.

Common expression forms

Expressions are built from values, names, operators, and constructs that access or create data. These common forms cover much of the syntax encountered in everyday JavaScript:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Identifiers and literals: price, 42, "hello", true, null, undefined, and 12n (a BigInt literal).
  • this: refers to the current this value in the relevant execution context.
  • Array and object literals: [1, 2] creates an array; { name: "Ada" } creates an object when used in an expression context.
  • Function and class expressions: const double = function (n) { return n * 2; }; creates a function value; class expressions similarly produce class values.
  • Regular-expression and template literals: /ab+/ creates a regular expression; `Hello, ${name}` evaluates to a string containing name.
  • Grouping: (a + b) is a grouped expression. Parentheses can make intended order clearer.
  • Property access and optional chaining: user.name accesses a property; user?.name yields undefined if user is null or undefined, rather than throwing for that access.
  • Calls and construction: Math.max(a, b) calls a function and returns the larger argument; new Date() constructs an object.
  • Other language forms: super accesses superclass functionality in class contexts, and import("./module.js") dynamically loads a module and returns a promise.

These examples include primary and left-hand-side expression forms documented in the MDN operator reference. Whether a particular form is valid depends on its context: for example, super is only legal in specific class contexts.

How JavaScript operators combine expressions

An operator acts on one or more operands to form an expression. The operands may be literals, variables, function calls, or other expressions. Operators are commonly grouped by what they do:

Operator family Example What it does
Assignment x = 7 Stores a value in a binding or property and evaluates to the assigned value.
Arithmetic a + b, a * b Performs numeric arithmetic, subject to JavaScript’s operand rules.
Comparison and relational a === b, a < b Compares values and usually produces a Boolean result.
Logical ready && start() Combines conditions or selects an operand using short-circuit evaluation.
Bitwise flags & mask Applies bit-level operations to numeric operands.
BigInt 10n + 2n Performs integer arithmetic using BigInt values; BigInt and Number operands generally cannot be mixed in arithmetic.
String "Hi, " + name Can concatenate strings; the plus operator’s behavior depends on its operands.
Conditional (ternary) ok ? yesValue : noValue Evaluates the condition and then evaluates one of the two result expressions.
Comma (first(), second()) Evaluates expressions from left to right and produces the value of the last one.
Unary !ready, typeof value Uses one operand to produce a result or perform an operation.

These families are a practical introduction, not a promise that each operator behaves identically for every type. For example, + can add numbers or concatenate strings, and logical operators can return one of their operand values rather than a Boolean. When operand types matter, consult the specific operator’s behavior in the MDN reference.

Unary, binary, and ternary operators

Operator arity means the number of operands the operator takes. A unary operator takes one operand, as in !ready or typeof value. A binary operator takes two, as in a + b. The conditional operator is ternary: ok ? yesValue : noValue has three parts—the condition and two alternatives.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Increment and decrement operators are unary, and placement affects the value of the expression. In count++, the expression evaluates to the old value before increasing count; in ++count, it increases first and evaluates to the new value. If the value is not used, both forms still change count.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why parentheses and precedence change results

Precedence determines which operator is applied first when an expression contains different operators without explicit grouping. Multiplication has higher precedence than addition, so 1 + 2 * 3 evaluates as 1 + (2 * 3), producing 7. Parentheses group an expression and can override that default: (1 + 2) * 3 produces 9.

When operators share a precedence level, associativity determines the grouping direction. For example, subtraction groups left to right: 10 - 3 - 2 means (10 - 3) - 2, which evaluates to 5. Assignment groups right to left: a = b = 7 assigns 7 to b, then assigns the resulting value to a.

Use parentheses when they make the intended grouping easier to see, even if precedence already makes the result unambiguous. For a complete ordering and associativity table, see MDN’s operator precedence reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Where expressions appear in real code

Once you recognize that expressions supply values, their role in common code becomes clearer:

  • Initializer: const total = price * quantity; evaluates an expression and stores its value in total.
  • Condition: if (items.length > 0) { ... } evaluates the comparison to decide which branch runs.
  • Argument: Math.max(scoreA, scoreB) passes expressions as function arguments and evaluates to the returned maximum.
  • Return value: return user.name; evaluates the property access and returns its value from the function.
  • Standalone effect: logResult(total); calls a function as an expression statement; the call’s value, if any, is discarded unless used.

The distinction is useful when debugging: ask what value an expression produces, what effects it causes, and which surrounding statement uses it. A value can be correct while a side effect happens at an unexpected time, especially when short-circuiting or increment operators are involved.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.