Home Basics JavaScript logical operators

JavaScript logical operators

The following operators are known as JavaScript logical operators. Logical operators perform logical operations and return a boolean value, either true or false.

  • ! (Logical NOT)
  • || (Logical OR)
  • && (Logical AND)

Here is a table showing these operators

Operator Description Example
&& Logical AND: true if both the operands are true, else returns false x && y
|| Logical OR: true if either of the operands is true; returns false if both are false x || y
! Logical NOT: true if the operand is false and vice-versa. !x

lets see examples of these

// logical AND

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

// logical OR

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

// logical NOT

console.log(!true); // false

 

You may also like