Plenty of π
Module 3: Operators and User Interaction
Logical and Comparison Operators

Comparison Operators: Compare two values and return a boolean (true or false).

  • == (Equal to): Checks if values are equal (performs type coercion). 5 == "5" is true.
  • === (Strictly equal to): Checks if values AND types are equal. 5 === "5" is false.
  • != (Not equal to): 5 != 8 is true.
  • !== (Strictly not equal to): 5 !== "5" is true.
  • > (Greater than): 5 > 3 is true.
  • < (Less than): 5 < 3 is false.
  • >= (Greater than or equal to): 5 >= 5 is true.
  • <= (Less than or equal to): 5 <= 3 is false.

Logical Operators: Combine or modify boolean expressions.

  • && (Logical AND): Returns true if both operands are true. true && false is false.
  • || (Logical OR): Returns true if at least one operand is true. true || false is true.
  • ! (Logical NOT): Inverts the boolean value. !true is false.
let age = 20;
let hasLicense = true;
console.log(age >= 18 && hasLicense); // true
console.log(age < 18 || !hasLicense); // false

Recommendation: Use strict equality (=== and !==) to avoid unexpected behavior from type coercion.