5. Operators and control flow
Beyond the arithmetic/comparison basics, three operators pull real weight in modern code:
const user = null;
user?.profile?.name; // optional chaining: undefined instead of throwing
const name = user?.name ?? "Anonymous"; // nullish coalescing: only falls back on null/undefined
// vs the older, buggier `||` fallback:
const count = 0;
count || 10; // 10 — WRONG if 0 is a valid value, `||` treats it as falsy
count ?? 10; // 0 — CORRECT, ?? only falls back on null/undefined
switch uses === semantics and needs explicit break (fallthrough is
intentional and common for grouping cases); prefer object-literal lookup
tables or a Map over long if/else if chains for pure value dispatch.