Cosmovex Tools

Practising JavaScript interview questions? Implement debounce and Promise.all live

JS interview questions with PairPad

The pad opens with two of the most-asked frontend interview tasks, debounce(fn, wait) and promiseAll(list), as empty stubs above four async tests that use real timers. Press Run and the console shows which tests fail; implement both until all four print PASS, alone or with a partner in a shared room.

  1. Press Run (Ctrl/Cmd+Enter). The tests use setTimeout and await, and the console prints FAIL for three of them against the stubs.
  2. Implement debounce: one timer in a closure, cleared and restarted on every call. Run again; the first test passes when only "hello" is recorded.
  3. Implement promiseAll without Promise.all. Results must come back in input order even though the second promise settles first, and the first rejection must reject the whole call.
  4. To practise as a mock interview, press Share and send the link. One person codes while the other asks follow-ups: leading-edge debounce, cancel(), or a concurrency-limited version of promiseAll.
  5. Keep hints.md closed until you are stuck; it lists the two details people most often miss.
javascript interview coding questions implement debounce javascript interviewimplement promise.all javascriptjavascript interview practice onlinefrontend interview questions practicejavascript mock interview online
Open PairPad Free · Pro $29 one-time · no account

What to know

These two questions show up in frontend interviews because they test the event loop rather than syntax. debounce checks that you understand closures and timers: the timer id must live in the closure, every call clears it, and the wrapped function receives the last call's arguments. promiseAll checks that you can build a promise from scratch, keep results in input order when promises settle out of order, treat plain values as already-resolved, and settle exactly once.

The tests run with real timers in a browser worker, so they behave like code in a tab: sleep(30, 'a') really takes 30 ms, and the order test is meaningful because the second promise settles first. The run finishes when every timer and pending fetch has settled, and is stopped after five seconds if something never settles, for example a promiseAll that forgets to resolve on an empty list.

Two common bugs the tests catch: pushing results into an array as they arrive (the order test fails, giving b, a, c), and resolving when the counter reaches list.length without handling length 0 (the empty-list test hangs until the five-second limit). One the tests do not catch, which an interviewer will ask about: if you call fn with this-less fn(...args), a debounced method loses its object, so use fn.apply(this, args) and a regular function for the wrapper.

Everything runs in your browser; nothing is executed on a server. Free rooms are deleted 24 hours after the last activity, so finish a practice set in one sitting or keep it in a permanent Pro room. Pro ($29 once) adds interviewer notes only you can read, a question bank of saved rooms, and a keystroke replay for reviewing a mock interview afterwards.

Updated · Cosmovex

Questions

Why does the order test fail with an array push?

The second input settles after 10 ms and the first after 30 ms, so pushing gives [b, a, c]. Store each value at its index (results[i] = value) and count completions instead.

Do setTimeout and await really work in the pad?

Yes. The code runs in a browser worker with real timers, promises and top-level await, and the run ends when all timers and pending promises from fetch have settled.

What should promiseAll do with an empty array?

Resolve immediately with []. That is how Promise.all behaves, and an implementation that only resolves when a counter reaches list.length never resolves for an empty list.

What follow-up questions might an interviewer ask?

Common ones are a leading-edge (immediate) debounce, adding cancel() and flush(), throttle versus debounce, Promise.allSettled and Promise.race, and a promiseAll that runs at most N tasks at a time.

Can I practise with someone else?

Yes. Press Share and send the link; both of you edit the same file with live cursors and see the same console output after every Run.

The free plan covers everything on this page. PairPad Pro ($29, paid once) is described on the PairPad page.