Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The logical OR (||) (logical disjunction) operator for a set of operands is true if and only if one or more of its operands is true. It is typically used with boolean (logical) values. When it is, it returns a Boolean value. However, the || operator actually returns the value of one of the specified operands, so if this operator is used with non-Boolean values, it will return a non-Boolean value.
If x can be converted to true, returns x; else, returns y.
If a value can be converted to true, the value is so-called truthy. If a value can be converted to false, the value is so-called falsy.
Examples of expressions that can be converted to false are:
Even though the || operator can be used with operands that are not Boolean values, it can still be considered a boolean operator since its return value can always be converted to a boolean primitive. To explicitly convert its return value (or any expression in general) to the corresponding boolean value, use a double NOT operator or the Boolean() constructor.
The logical OR expression is evaluated left to right, it is tested for possible "short-circuit" evaluation using the following rule:
(some truthy expression) || expr is short-circuit evaluated to the truthy expression.
Short circuit means that the expr part above is not evaluated, hence any side effects of doing so do not take effect (e.g., if expr is a function call, the calling never takes place). This happens because the value of the operator is already determined after the evaluation of the first operand. See example:
The following expressions might seem equivalent, but they are not, because the && operator is executed before the || operator (see operator precedence).
The following code shows examples of the || (logical OR) operator.
Note: If you use this operator to provide a default value to some variable, be aware that any falsy value will not be used. If you only need to filter out null or undefined, consider using the nullish coalescing operator.
The following operation involving booleans:
is always equal to:
The following operation involving booleans:
is always equal to:
As logical expressions are evaluated left to right, it is always possible to remove parentheses from a complex expression following some rules.
The following composite operation involving booleans:
is always equal to:
| ECMAScript® 2027 Language Specification # prod-LogicalORExpression |
Enable JavaScript to view this browser compatibility table.
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.