JavaScript Logical Operators

The Comparison Operators are used to compare two variables. What if we want to compare more than one condition? Very simple, JavaScript Logical Operators will do the trick for you.

These operators are used to combine two or more conditions and perform the logical operations using && (AND), || (OR), and ! (NOT). The below table describes them.

OPERATORSNAMEDESCRIPTIONEXAMPLE
&&ANDIt will return True when both conditions are trueIf (age > 18 && age <=35)
||ORIt will return True when at least one of the conditions is trueIf (age > 35 || age < 60)
!NOTIf the condition is True, NOT operator makes it falseIf age = 18 then, !( age = 18) returns false.

Let us see the truth tables behind the JavaScript Logical Operators for a better understanding

&& (JS LOGICAL AND)

Condition 1Condition 2Condition 1 && Condition 2
TrueTrueTrue
TrueFalseFalse
FalseTrueFalse
FalseFalseFalse

|| (JS LOGICAL OR)

Condition 1Condition 2Condition 1 || Condition 2
TrueTrueTrue
TrueFalseTrue
FalseTrueTrue
FalseFalseFalse

Please refer to the Comparison Operators article.