JavaScript || Logical OR Operator
The logical OR operator (||) returns the first truthy value, or the last value if none are truthy. In conditions it means at least one must be true.
Description
The logical OR operator || is true in a condition when at least one operand is truthy. It returns the first operand if it's truthy, otherwise the second, and short-circuits so the right side is only evaluated when needed.
It has long been used for defaults, name || 'Guest', but it also replaces valid falsy values like 0 and ''. When only null and undefined should be replaced, use ?? instead.
You can chain several values, a || b || c, to pick the first truthy one. Mixing || with ?? in one expression without parentheses is a syntax error, because their combined meaning would be unclear. || has lower precedence than &&, so a || b && c means a || (b && c); parentheses make the intent obvious.
Properties
- Operator
||- Category
- Logical
- Precedence
- 3 (1 is lowest, 18 is highest)
- Associativity
- left-to-right
Syntax
x || yExample
Browser Support
The following information will show you the current browser support for the || operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





