Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Logical OR (||)

Logical OR: returns the first truthy value.

Available since: ES1

Syntax

a || b

Examples

In conditions — at least one is true:

const age = 70;
 
console.log(age < 18 || age > 65);

Output:

true

It returns the value itself, not just true or false:

console.log('' || 'default');
console.log('Anna' || 'default');
console.log(0 || null);

Output:

default
Anna
null

Notes

If the left side is truthy the right side is not evaluated at all. For defaults where 0 or an empty string are valid, use ??.

See also

In the tutorial

  • Logical operators — JavaScript logical operators — AND, OR, NOT, their precedence, default values with || and the ?? operator.

Thanks for reading!

Donate to the site — we work hard for you.