JavaScript
Cheat sheet and 30-second answers
One page of ready-to-say answers for the night before.
Thirty seconds each, out loud, no notes. If any answer wobbles, follow its link back to the full page.
Language
| Question | 30-second answer |
|---|---|
var vs let vs const? | Function scope and hoisted-undefined versus block scope and dead zone; const locks rebinding, not contents. (variables) |
== vs ===? | Strict compares type and value; loose converts — 0 == "" is true. Always ===. (types) |
null vs undefined? | Missing versus deliberately empty; JS makes undefined, you choose null. (types) |
| Copy an object? | Spread is shallow; structuredClone is deep but drops functions. (values) |
| Arrow vs function? | Arrows inherit this and can't be constructed; functions get this from the call. (functions) |
| What is a closure? | A function plus its creation scope, live-linked — privacy and callbacks. (closures) |
Predict this? | Read the call: method, bare, explicit, new; arrows inherit. (this) |
| Classes real? | Constructors plus prototypes with safer defaults; debug in prototypes. (objects) |
map vs forEach? | map returns a transformed array; forEach returns nothing and only side-effects. (arrays) |
| Sort numbers? | Never default sort — sort((a, b) => a - b) on a copy. (arrays) |
?? vs ||? | Nullish defaults only nullish; OR defaults all falsy. Zero stays with ??. (syntax) |
Running and async
| Question | 30-second answer |
|---|---|
| Call stack? | Frames push on call, pop on return; overflow means no base case. (stack) |
| Sync, promise, timer order? | Script, microtasks drain, then timers — every time. (loop) |
| What is a promise? | Pending once, then fulfilled or rejected forever; return every step. (promises) |
all vs allSettled vs race vs any? | Strict, reporter, first-settled, first-success. (promises) |
await in a loop? | Serializes independent work — launch all, gather once. (async) |
fetch gotchas? | Two awaits plus ok check; rejects on network failure only. (fetch) |
| Debounce vs throttle? | Silence-then-fire versus at-most-per-interval. (perf) |
| Event delegation? | One parent listener, event.target.closest — covers future rows. (dom) |
| Memory leaks? | Stray timers, detached DOM, unbounded caches — every setup needs teardown. (memory) |