Logical OR (||)

Returns the first truthy operand, or the last operand if all are falsy.

Since ES1 Spec ↗

Syntax

left || right

Returns

any — `left` if it is truthy, otherwise `right`.

Examples

console.log(false || "fallback");
console.log("first" || "second");
Output
fallback
first
const name = "" || "anonymous";
console.log(name);
Output
anonymous
const count = 0 || 10;
console.log(count);
Output
10

Notes

- Short-circuits: `right` is only evaluated if `left` is falsy. - Treats any falsy value as "missing"; use `??` when only `null` and `undefined` should fall back.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also