JS Logical Operators

Logical Operators

Ø  Logical operators are typically used to determine the logic between variables or values. 

Ø  These types of operators help us in connecting either one or more conditions and return a Boolean value, either true or false.

&& - AND operator

·       It checks whether the two operands are true. It returns true, otherwise, it returns false.

·       Example: a && b

|| - OR operator

·       It checks whether any of the operands are True. It returns True, otherwise, returns false.

·       Example: a || b

 ! - NOT operator

·       For reversing the Boolean result of an operand or condition.

·       Example: ! a

Example of all logical operators:

// logical AND

console.log(true && true); // True

console.log(true && false); // False

console.log(false && false); // False


// logical OR

console.log(true || false); // True

console.log(true || true); // True

console.log(false || false); // False

// logical NOT

console.log(!true); // False

console.log(!false); // True


Logical operators are used in decision-making and loops.

Leave a comment
No Cmomments yet