JavaScript Promises and Async/Await Interview Tips: Event Loop, Errors, and Clean Answers
Asynchronous JavaScript is one of the most common topics in front-end and Node.js interviews. It shows up as "what does this log?" puzzles, as "implement Promise.all yourself," and inside practical tasks like fetching data with retries. Interviewers use it because it reveals whether you actually understand how JavaScript runs, not just its syntax.
These JavaScript promises and async/await interview tips cover what to review and how to explain it under pressure.
1. Explain the event loop in 30 seconds
Have a short, accurate explanation ready:
JavaScript runs on a single thread with a call stack. When the stack is empty, the event loop first drains the microtask queue, which holds promise callbacks and
queueMicrotaskjobs. Then it takes the next macrotask, such as asetTimeoutcallback or an I/O event, and repeats.
The key point most questions test: microtasks run before the next macrotask. That's why a resolved promise's .then runs before a setTimeout(fn, 0).
2. Practice the classic output question
console.log('A');
setTimeout(() => console.log('B'), 0);
Promise.resolve().then(() => console.log('C'));
console.log('D');
The output is A, D, C, B. Explain it step by step: synchronous logs first, then the microtask, then the timer. Narrating the queues out loud matters as much as the final answer.
Add an async function to the mix and practice again. Remember that code inside an async function runs synchronously until the first await; everything after the await continues as a microtask.
3. Know the promise states and chaining rules
- A promise is pending, then either fulfilled or rejected, and it settles only once.
.thenreturns a new promise. Returning a value fulfills it; returning a promise adopts that promise's result; throwing rejects it.- A missing
returninside.thenis a classic bug: the next step receivesundefinedand doesn't wait.
4. Error handling patterns
Interviewers often probe whether you handle failures properly.
- With chains, put
.catchat the end, and know that it also catches errors thrown in earlier.thencallbacks. - With async/await, use
try/catcharound the awaited calls, andfinallyfor cleanup like hiding a spinner. - Mention unhandled rejections: in Node.js they can crash the process in modern versions, and in browsers they trigger an
unhandledrejectionevent.
5. Promise combinators
Know when to use each:
| Method | Resolves when | Rejects when |
|---|---|---|
Promise.all | all fulfill | any rejects (fail fast) |
Promise.allSettled | all settle | never rejects |
Promise.race | first settles | first settles with rejection |
Promise.any | first fulfills | all reject (AggregateError) |
A good line: "If I need every result and one failure makes the rest useless, Promise.all. If I want partial results, allSettled."
6. Sequential vs parallel awaits
A frequent code-review question:
const a = await getA();
const b = await getB();
This runs one after the other. If the calls are independent, start both first and await together with Promise.all([getA(), getB()]). Mention the trade-off: parallel is faster but can overload a rate-limited API, so sometimes you want a concurrency limit.
7. Common implementation prompts
Practice writing these from scratch:
Promise.all: track results by index, count completions, reject on the first error, and handle an empty array by resolving immediately.sleep(ms):new Promise(resolve => setTimeout(resolve, ms)).- Retry with backoff: loop up to N attempts,
awaitthe call, catch errors, and wait longer each time. - Timeout wrapper: race the task against a promise that rejects after a delay.
- Concurrency limiter: run at most K tasks at once, starting a new one each time another finishes.
For each, say the edge cases out loud: empty input, non-promise values, and errors partway through.
8. Pitfalls interviewers like to ask about
- Using
awaitinsideforEachdoesn't wait; usefor...oforPromise.allwithmap. - Forgetting
returnin.thenchains. - Wrapping an existing promise in
new Promiseunnecessarily. - Swallowing errors with an empty
catch. - Assuming
setTimeout(fn, 0)runs immediately.
9. How to structure your answer
- Restate what the code or task should do.
- For output questions, walk through the call stack, microtasks, and macrotasks in order.
- For implementation tasks, outline the approach, then code in small pieces.
- Test with a tiny example, including a rejection case.
- Mention trade-offs like parallelism versus rate limits.
A short practice plan
- Day 1: five event-loop output puzzles, explained out loud.
- Day 2: implement
Promise.allandPromise.allSettled. - Day 3: retry with backoff and a timeout wrapper.
- Day 4: a concurrency limiter, then a practical fetch task with loading and error states.
- Day 5: a full timed mock mixing one output question and one implementation.
Practice it under pressure
Async questions are easy to reason about slowly and much harder to narrate live. Rehearse with a timer and say each queue step out loud until it feels routine.
Luna Interview is a practice and calm-under-pressure companion for that kind of rehearsal, with timed sessions and structured hints in your browser. Try Luna Interview at https://lunainterview.xyz/.
Rehearse with an AI interview copilot, then browse commonly reported interview questions.