Early previewThis guide is in development. Items tagged verify are still being checked against official docs.
nebx Learn
GitHub
Menu
Home/JavaScript/Tips & tricks
JS

JavaScript

The language of the web, on the client, the server and the edge.

Paradigm
Multi-paradigm, prototype-based, functional
Typing
Dynamic, weak (TypeScript adds static types)
Memory
Garbage collected
Runs
V8 / SpiderMonkey / JSC engines (JIT)
Concurrency
Single-threaded event loop, workers

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 destructuring

Promise.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, cycles

Saved in this browser only. Part of Clean code foundations (0/5).