Values, types and equality
Seven primitives and objects
string, number, bigint, boolean, undefined, symbol, null, and then objects (arrays, functions,
dates, maps... are objects). Primitives are copied by value; objects by reference.
const a = { n: 1 }; const b = a; b.n = 2;
console.log(a.n); // 2: same object
typeof null // "object" (a famous old bug)
typeof [] // "object"; use Array.isArray
== vs ===
=== compares without converting types. == converts first, with surprising rules ("" == 0 is true). Use ===
everywhere; the one common exception is x == null, which checks for both null and undefined.
Truthy and falsy
Falsy: false, 0, -0, 0n, "", null, undefined, NaN. Everything else is truthy, including "0", [] and {}.
Modern helpers you'll see in app.js
const name = user?.profile?.name ?? "friend"; // optional chaining + nullish coalescing
const { x, y } = point; // destructuring
const all = [...list, item]; // spread
const n = +localStorage.getItem("inpace-plan-at") || 0; // unary + converts to a number
?? only falls back on null/undefined; || also falls back on 0 and "". Interviewers love that difference.