JS: Module 2

← Dashboard
Module 2: The Logic Switch

Conditionals

Make decisions with if/else. Use comparison operators (===, >, <) and switch for multiple options.

// if/else - If cup is empty, refill
if (cupsLeft === 0) {
  refill();
} else {
  pour();
}

// switch - Menu options
switch (order) {
  case "latte": price = 4; break;
  case "espresso": price = 2; break;
  default: price = 3;
}
Pro Tip

Use === (strict) instead of == to avoid type coercion surprises.

Operators

===, !==, >, <, >=, <= for comparisons.