top of page

Logical operators in JavaScript

In JavaScript there are three operators we can use for logical operations.

Operator
Operation
&&
Logical AND
||
Logical OR
!
Logical NOT

We use these logical operators to evaluate to operands that typically has boolean value of true or false

 

The && which is logical AND will evaluate two operands and return true only of both operands them selves are true. If not it will return false. We use && AND to control the direction of the script by checking if two conditions are met. If both conditions are satisfied the script will go in one direction, if not it will choose another path.    

The || logical OR is unlike the && logical AND as it does not both operands to be true. It returns boolean true if only one is true. So if one of the operands is true, then it returns boolean true. It needs both operands to be false to return false.

The last logical operator is a single ! that is the logical NOT. When placed before a single operand it returns the inverse the value of the operand.

bottom of page