Get to know MDN better
An expression statement is an expression used in a place where a statement is expected. The expression is evaluated and its result is discarded — therefore, it makes sense only for expressions that have side effects, such as executing a function or updating a variable.
An arbitrary expression to be evaluated. There are certain expressions that may be ambiguous with other statements and are thus forbidden.
Apart from the dedicated statement syntaxes, you can also use almost any expression as a statement on its own. The expression statement syntax requires a semicolon at the end, but the automatic semicolon insertion process may insert one for you if the lack of a semicolon results in invalid syntax.
Because the expression is evaluated and then discarded, the result of the expression is not available. Therefore, the expression must have some side effect for it to be useful. Expression statements are commonly:
Others may also have side effects if they invoke getters or trigger type coercions.
In order for an expression to be used as a statement, it must not be ambiguous with other statement syntaxes. Therefore, the expression must not start with any of the following tokens:
Therefore, all of the following are invalid:
More dangerously, sometimes the code happens to be valid syntax, but is not what you intend.
To avoid these problems, you can use parentheses, so that the statement is unambiguously an expression statement.
You can avoid almost all use of control flow statements using expression statements. For example, if...else can be replaced with ternary operators and logical operators. Iterative statements like for or for...of can be replaced with array methods.
Warning: This only demonstrates a capability of the language. Excessive use of expression statements as a substitute for control-flow statements can make code much less readable.
| ECMAScript® 2027 Language Specification # sec-expression-statement |
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.