JavaScript Coding Interviews
The JavaScript round in the order the topics build: how to run it, closures and this, the array polyfills, timers and promises, the lodash classics, a data-selection question, then the DOM — with the one bug each is known for.
How Do You Approach a JavaScript Coding Question?
Frontend · Clarify the runtime and the edges, say which spec cases you are skipping, then dodge the one bug each classic is known for.
Frontend · A function plus the bindings of the scope it was created in — bindings, not snapshots.
Predict the Output: var and let in a Loop With Timers
Frontend · var gives the loop one shared binding; let gives each iteration its own.
Implement Function.prototype.bind
Frontend · A closure over thisArg and the leading arguments; the original runs later, with the call's own arguments appended.
Frontend · Pre-size the output so holes stay holes, and forward thisArg.
Implement Array.prototype.filter
Frontend · Skip holes, forward thisArg, and keep the elements whose callback is truthy.
Implement Array.prototype.reduce
Frontend · A missing initial value versus an undefined one — and the TypeError when there's nothing to reduce.
Predict the Output: Promise and Timer Order
Frontend · A promise resolved inside a timer, two more timers, and a microtask: the event loop decides the order.
Frontend · A one-way state machine, a handler queue, and every callback in a microtask.
Frontend · A leading call, then at most one call per window — with a trailing call that carries the latest arguments.
Frontend · Store results by index, count down, resolve an empty input at once, reject on the first failure.
Frontend · Record every outcome by index as { status, value | reason }; it never rejects, and an empty input resolves at once.
Frontend · Resolve on the first fulfilment; reject only when every input has failed, with an AggregateError whose errors follow input order.
Retry With Exponential Backoff
Frontend · Try, wait, multiply the wait, try again: the first fulfilment wins, the last failure is the error, and no wait follows it.
Frontend · Collect arguments until fn.length have arrived — with a fresh array per call so partials stay independent.
Implement Array.prototype.flat
Frontend · Depth, holes and Infinity — without recursion, so 100,000 levels can't overflow the stack.
Frontend · Cycles, shared references, Date, RegExp, Map, Set, prototypes and symbol keys: everything spread and JSON get wrong.
Frontend · Strings and numbers pass through, objects add their truthy keys, arrays recurse, falsy values vanish, one space between.
Frontend · A map from event name to listener list; copy the list before emitting so listeners can unsubscribe mid-emit.
Frontend · A closure over a Map keyed on every argument — and has, not truthiness, so 0 and undefined still hit.
Frontend · A recursive serializer with the real rules: undefined vanishes from objects but becomes null in arrays, and strings need escaping.
Frontend · Merge per user with a Map re-inserted on every session so order follows the last one, then filter the merged rows.
Implement getElementsByTagName
Frontend · A depth-first walk over children comparing upper-cased tag names: document order for free, text nodes never seen.
A Tooltip Library From data Attributes
Frontend · One tooltip node, delegated listeners, keyboard focus and Escape — in plain DOM, not a component.