JavaScript OR

JavaScript OR Operator is used to perform logical OR operation on two boolean operands.

OR Operator is usually used in creating complex conditions like combining two or more simple conditions.

OR Operator Symbol

The symbol used for OR Operator is ||.

ADVERTISEMENT

Syntax

The syntax to use OR Operator with operands a and b is

a || b

OR Operator supports chaining. For example, the syntax to write a condition with four boolean values is

a || b || c || d

The above expressions returns true if any of the operands is true.

OR Truth Table

The following truth table provides the output of OR operator for different values of operands.

aba || b
truetruetrue
truefalsetrue
falsetruetrue
falsefalsefalse

OR Operation returns true, if any of the operands is true, else, it returns false.

Examples

In the following example, we take two Boolean variables with different combinations of true and false, and find their logical OR output.

index.html

In the following example, we use logical OR Operator in If Statement’s Condition to combine two simple conditions to form a complex condition.

index.html

Conclusion

In this JavaScript Tutorial, we learned about Logical OR Operator, its syntax, and usage with examples.