JS: Boolean Operators

By Xah Lee. Date: . Last updated: .

Logical And Operator

x && y
  • Return true if both Boolean(x) and Boolean(y) are true, else false.
  • If Boolean(x) is false, y is not evaluated.
// “and” operator
console.log(true && true);

Logical Or Operator

x || y
  • Return true if one of Boolean(x) or Boolean(y) is true, else return false.
  • If Boolean(x) is true, y is not evaluated.
// “or” operator
console.log(true || true);

Logical Not Operator

!x
  • Reverse the boolean value.
  • Return true if Boolean(x) is false, return false if Boolean(x) is true.
// “logical negation” operator
console.log(!false);

JavaScript. Operators