Interview Q&A / JavaScript
JavaScript interview questions
Closures, the event loop, this, promises and the core language questions every frontend round asks.
Prefer rapid revision? Practise JavaScript short interview answers →
- How do tasks and microtasks work in the JavaScript event loop?
JavaScript runs one piece of code at a time. After the current code finishes, it runs all waiting microtasks (like promise callbacks) before the next task (like a setTimeout callback).
IntermediateIn-depth2 min read - How does promise chaining work, and what happens after a catch?
Every then returns a new promise, resolved with whatever the handler returns, so calls chain. A thrown error skips later then handlers until a catch, and after a catch that returns a value, the chain continues normally.
IntermediateQuick answer1 min read - What is the difference between Promise.all, allSettled, race and any?
all waits for every promise and rejects on the first failure. allSettled waits for all and reports each outcome. race settles with the first promise to settle. any fulfills with the first success and rejects only if all fail.
IntermediateQuick answer1 min read - Write your own version of Promise.all.
Return a new promise. Keep a results array and a counter. Wrap each input in Promise.resolve, store its value at its index, and resolve when the counter reaches zero. Reject as soon as any input rejects.
IntermediateQuick answerCoding1 min read