🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Expressions_and_operators
Expressions and operators - JavaScript | MDN
This chapter describes JavaScript's expressions and operators, including assignment, comparison, arithmetic, bitwise, logical, string, ternary and more.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Statements › Expression_statement
Expression statement - JavaScript | MDN
More dangerously, sometimes the code happens to be valid syntax, but is not what you intend. ... // For some reason, you have a variable called `let` var let = [1, 2, 3]; function setIndex(index, value) { if (index >= 0) { // Intend to assign to the array `let`, but instead creates an extra variable! let[index] = value; } } setIndex(0, [1, 2]); console.log(let); // [1, 2, 3] // This is not an object literal, but a block statement, // where `foo` is a label and `1` is an expression statement.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Regular_expressions
Regular expressions - JavaScript | MDN
If using the RegExp constructor ... RegExp("a\\*b") create the same expression, which searches for "a" followed by a literal "*" followed by "b". The RegExp.escape() function returns a new string where all special characters in regex syntax are escaped....
🌐
W3Schools
w3schools.com › js › js_syntax.asp
JavaScript Syntax
// Define x as a variable let x; // Assign the value 6 to x x = 6; Try it Yourself » · An identifier is the name you give to a variable. ... An expression is a combination of values, variables, and operators, which computes to a value.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › expressions
What is a JavaScript Expression? - Mastering JS
In general, an expression is a snippet of code that evaluates to a value. A statement is a snippet of code that performs an action. Wherever JavaScript expects a statement, you can write an expression.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Function expressions
Function Expression: a function, created inside an expression or inside another syntax construct. Here, the function is created on the right side of the “assignment expression” =: // Function Expression let sum = function(a, b) { return a + b; }; The more subtle difference is when a function is created by the JavaScript engine.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › function
function expression - JavaScript | MDN
A function expression is very similar ... the same syntax as, a function declaration. The main difference between a function expression and a function declaration is the function name, which can be omitted in function expressions to create anonymous functions. A function expression can be used as an IIFE (Immediately Invoked Function Expression) which runs as soon as it is defined. See also the chapter about functions for more information. Function expressions in JavaScript are not hoisted, ...
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Regular_expressions › Cheatsheet
Regular expression syntax cheat sheet - JavaScript | MDN
Assertions include boundaries, which indicate the beginnings and endings of lines and words, and other patterns indicating in some way that a match is possible (including look-ahead, look-behind, and conditional expressions).
🌐
Flavio Copes
flaviocopes.com › javascript-expressions
JavaScript Expressions
March 17, 2018 - new //create an instance of a constructor super //calls the parent constructor ...obj //expression using the spread operator · See the spread operator tutorial · object.property //reference a property (or method) of an object object[property] object['property'] new object() new a(1) new MyRectangle('name', 2, {a: 4}) function() {} function(a, b) { return a * b } (a, b) => a * b a => a * 2 () => { return 2 } The syntax for calling a function or method · a.x(2) window.resize() → Get my JavaScript Beginner's Handbook ·
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-expressions-complete-reference
JavaScript Expressions Complete Reference - GeeksforGeeks
July 23, 2025 - JavaScript's expression is a valid set of literals, variables, operators, and expressions that evaluate a single value that is an expression.
🌐
Medium
medium.com › launch-school › javascript-expressions-and-statements-4d32ac9c0e74
JavaScript Expressions and Statements | by Madhu M | Launch School | Medium
December 25, 2018 - // Syntax of an if statement. If the expression following the if statement evaluates to a truthy value, statement 1 is executed else statement 2 is executed.if (expression) statement 1 else statement 2 · Looping statements includes the following statements: while, do/while, for and for/in. Jump statements are used to make the JavaScript ...
🌐
web.dev
web.dev › learn › javascript › functions › function-expressions
Function expressions | web.dev
You can create an arrow function wherever an expression is expected, for example, as a value assigned to a variable. In its most common form, an arrow function is made up of a pair of matched parentheses containing zero or more parameters, an arrow made up of a single equals sign and greater-than character (=>), and a pair of matched curly braces containing the function body: ... Under certain conditions, you can make the syntax even more compact.
🌐
Josh W. Comeau
joshwcomeau.com › javascript › statements-vs-expressions
Statements Vs. Expressions • Josh W. Comeau
At its core, an expression is a bit of JavaScript code that produces a value. ... Expressions can contain expressions. For example, how many expressions do you count in this chunk of JS code?
🌐
CSS-Tricks
css-tricks.com › an-introduction-to-javascript-expressions
An Introduction to JavaScript Expressions | CSS-Tricks
October 22, 2025 - JavaScript’s built-in console.log method doesn’t return a value. When the function is called it performs its work — the logging itself. Then, because it doesn’t have a meaningful value to return, it results in undefined. There’s nothing to do with that value, but your developer console informs you of the result of that evaluation before discarding it. Speaking of throwing results away, this brings us to a uniquely weird syntax: the comma operator.
🌐
Math.js
mathjs.org › docs › expressions › syntax.html
Expression syntax
There is a differing syntax for defining functions. Example: f(x) = x^2. There are custom operators like x + y instead of add(x, y). Some operators are different. For example ^ is used for exponentiation, not bitwise xor. Implicit multiplication, like 2 pi, is supported and has special rules. Relational operators (<, >, <=, >=, ==, and !=) are chained, so the expression 5 < x < 10 is equivalent to 5 < x and x < 10.
🌐
W3Schools
w3schools.com › js › js_regexp.asp
JavaScript Regular Expressions
Regex is a common shorthand for a regular expression. JavaScript RegExp is an Object for handling Regular Expressions.
🌐
2ality
2ality.com › 2012 › 09 › expressions-vs-statements.html
Expressions versus statements in JavaScript
The following code is an immediately invoked function expression. > (function () { return "abc" }()) 'abc' If you omit the parentheses, you get a syntax error (function declarations can’t be anonymous):
Top answer
1 of 12
69

Are all statements also expressions?

“Wherever JavaScript expects a statement, you can also write an expression. Such a statement is called an expression statement. The reverse does not hold: you cannot write a statement where JavaScript expects an expression. For example, an if statement cannot become the argument of a function.”

This is comes from a recent post by Axel Rauschmayer about this topic: Expressions versus statements in JavaScript

Hope it helps.

2 of 12
65

According to MDN:

An expression is any valid unit of code that resolves to a value.

As such, anything that can be used as an rvalue is an expression.

The criterion is not whether side effects exist. Expressions can definitely have side effects. E.g. a=2 is an expression as it has a value (2) and also assigns a value to a variable. Which is why you can do things like:

let a;
let b = 1 + (a = 2); // a is now 2 and b is 3

It is possible for the same (textual) block of code to be considered both an expression and a statement depending on the context. E.g. the text snippet function f(){} is an expression on line 1 and a statement in line 2 in the below code:

let g = function f() {};
function f() {};

So whether something is an expression or a statement cannot (in the general case) be determined by looking at a textual piece of code out of context; rather it is a property of a node in a syntax tree and can be decided only after the code is (mentally or actually) parsed.

Also, and perhaps more importantly, function statements (a.k.a function declarations) inside a function f form part of the execution context that gets created when function f is invoked. However, function expressions do not form part of that execution context.

One often quoted effect of that is that function declarations get "hoisted" whereas function expressions do not.

A more subtle effect can also be experimentally observed in deep recursions given that function statements take up space in the execution context whereas function expressions do not. E.g. the below code uses infinite recursion of a function f. Function f in the first case includes a function expression inside it, in the second case it includes the equivalent function declaration:

// Function Expression
{
    let i = 0;
    try {

        function f () {
            i++;
            (function g() {})(); // this is an expression
            f();
        }

        f();

    } catch (err) {
        console.log(`Function Expressions case: depth of ${i} reached. Error: ${err.name}`);
    }
}
// Function Declaration
{
    let i = 0;
    try {
        function f () {
            i++;
            function g() {}; // this is a statement
            g();
            f();
        }

        f();

    } catch (err) {
        console.log(`Functions Declarations case: depth of ${i} reached. Error: ${err.name}`);
    }
}

On my machine I consistently get the following (in node.js):

Function Expressions case: depth of 17687 reached. Error: RangeError
Functions Declarations case: depth of 15476 reached. Error: RangeError

… which is consistent with the fact that Function Declarations increase the amount of space necessary to hold an execution context and thus eat up stack space a little faster and so slightly decrease the maximum recursion depth.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Functions › Arrow_functions
Arrow function expressions - JavaScript | MDN
Returning object literals using the expression body syntax (params) => { object: literal } does not work as expected. ... const func = () => { foo: 1 }; // Calling func() returns undefined! const func2 = () => { foo: function () {} }; // SyntaxError: function statement requires a name const func3 = () => { foo() {} }; // SyntaxError: Unexpected token '{' This is because JavaScript only sees the arrow function as having an expression body if the token following the arrow is not a left brace, so the code inside braces ({}) is parsed as a sequence of statements, where foo is a label, not a key in an object literal.
🌐
Rl
hepunx.rl.ac.uk › ~adye › js10 › expr.html
JavaScript Values, Expressions, and Operators
JavaScript has the following kinds of expressions: ... The special keyword null denotes a null value. In contrast, variables that have not been assigned a value are undefined, and cannot be used without a run-time error. A conditional expression can have one of two values based on a condition. The syntax ...