Arithmetic, Comparison, and Logical Operators
JavaScript's arithmetic operators (+ - * / % **) work as expected, but comparison and logical operators have a few sharp edges worth knowing early.
console.log(2 ** 10); // 1024 — exponentiation
console.log(5 % 2); // 1 — remainder
console.log(1 == "1"); // true — loose equality, coerces types
console.log(1 === "1"); // false — strict equality, no coercion
const isLoggedIn = false;
const user = isLoggedIn && getUser(); // short-circuits, getUser() never runs
Always prefer === and !== over == and != — loose equality coerces operands to a common type in ways that produce surprising results, like "" == 0 evaluating to true.
Logical operators &&, ||, and ! don't just return booleans; && and || return one of their actual operands, which is why they're commonly used for short-circuit guards and default values, e.g. const name = input || "Guest".