JavaScript Logical Operators

๐Ÿ“˜ What are Logical Operators?

Logical operators are used to combine or invert boolean values. They always return true or false.

๐Ÿงฎ Logical Operators

  • && AND - returns true if both operands are true
  • || OR - returns true if at least one operand is true
  • ! NOT - inverts the boolean value

๐Ÿ’ป Examples

let a = true;
let b = false;

console.log(a && b); // false
console.log(a || b); // true
console.log(!a);     // false
            

๐Ÿงช Try It Yourself

Click the button to see logical operators in action: