JavaScript Logical OR (||) Operator

Logical OR Operator

Logical OR operator takes two operands, and returns true if any of the left or right operand is true, or false otherwise.


|| symbol is used for logical OR operator

a || b

Truth Table of OR Gate

The following truth table provides the output of OR operator for possible operand values.

aba || b


1. Check if num is positive or an even number.

let num = 11;
if ((num > 0) || (num % 2 == 0)) {
    console.log('num is positive, even, or both');
} else {
    console.log('num is neither positive nor even');

In the above example, left operand a is (num > 0) and right operand b is (num % 2 == 0). For given value of num, a is true and b is false. if-condition is true, and therefore if-block is run.