Skip to content

Day 4: Arithmetic, Comparison & Logical Operators

Perform calculations, evaluate comparisons, and construct compound conditions.

let balance = 100;
balance += 50; // 150
balance -= 20; // 130
balance *= 2; // 260
balance /= 4; // 65
const remainder = 10 % 3; // 1 (modulo)

Always use strict equality (===) and strict inequality (!==)!

5 === '5'; // false (checks value AND type)
5 == '5'; // true (loose equality coerces types, dangerous!)
  • && (AND): True only if BOTH conditions are true.
  • || (OR): True if AT LEAST ONE condition is true.
  • ! (NOT): Inverts the boolean value.
const hasLicense = true;
const isAdult = true;
const canDrive = hasLicense && isAdult; // true
  1. Write 5 comparison expressions evaluating combinations of numbers and strings using both == and ===.
  2. Construct a compound logical condition testing if a user is eligible for a discount (e.g., student OR age under 25).