Tips & tricks
Small idioms with a big payoff.
Optional chaining and nullish coalescing
Safe access and defaults that don't swallow 0 or empty strings.
const city = user?.address?.city ?? "Unknown"; // no TypeError, keeps "" and 0
const { retries = 3, timeout = 5000 } = options; // defaults while destructuringPromise.allSettled
Run tasks in parallel and keep partial results.
const results = await Promise.allSettled([fetchA(), fetchB(), fetchC()]);
const ok = results.filter((r) => r.status === "fulfilled").map((r) => r.value);
const failed = results.filter((r) => r.status === "rejected");structuredClone
Built-in deep copy, available in modern browsers and Node.js 17+.
const copy = structuredClone(original); // deep copy, handles Map, Set, Date, cyclesSaved in this browser only. Part of Clean code foundations (0/5).