Favorites

JavaScript || Logical OR Operator

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
||
JavaScript Logical OperatorThis operator is supported by all modern browsers.
Updated 28th November 2026

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 || y

Example

const isWeekend = false, isHoliday = true;
console.log(isWeekend || isHoliday);
console.log('' || 'fallback');
console.log(0 || 10, 0 ?? 10);

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.

This operator is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee