JavaScript Introduction | Operators | Logical Operators

Logical Operators

Logical operators evaluate a given logical expression and return true or false.

The && operator and the || operator are binary operators with two operands, and their operands are associated from left to right.

The ! operator is a unary operator with only one operand, and its operand is associated from right to left.

Logical operator Description
&& Returns true when all logical expressions are true. (logical AND operation)
|| Returns true when at least one logical expression is true. (logical OR operation)
! Returns false when the result of the logical expression is true, and true when it is false. (logical NOT operation)

The following truth table shows every result of the logical operators.

A B A && B A || B !A
true true true true false
true false false true false
false true false true true
false false false false true