JavaScript Async Interview Questions: Promises, async/await, and the Event Loop
Reviewed by Mark Dickie · Last updated
5 questions on this page you can answer and see marked on the spot. Go to the first one
JavaScript async code is code that starts work now and handles the result later, using callbacks, promises, and async/await. Interviewers mostly test whether you can predict execution order, which depends on the event loop and the microtask queue, and whether you can handle errors across chained or parallel operations. Expect to explain why a resolved .then() callback runs before a setTimeout of zero, and what Promise.all does when one input rejects. The quiz below covers those cases.
Which async JavaScript topics come up in interviews?
| Topic | What to be able to explain |
|---|---|
| Event loop and microtasks | Why a resolved .then() callback runs before setTimeout(fn, 0), and where queueMicrotask fits |
| Promise.all vs Promise.allSettled | Promise.all rejects on the first rejection; allSettled waits and reports each outcome |
| async/await error handling | A rejected await throws inside the async function, so try/catch catches it; a call without await lets the rejection escape |
| Sequential vs parallel awaits | Two awaits in a row run one after the other; creating both promises first runs them concurrently |
| Unhandled rejections | Node 15+ exits the process on an unhandled rejection by default |
| Cancellation | AbortController aborts a fetch, but it cannot stop server-side work that already started |
How should you practise these before the interview?
- Predict the output of a snippet that mixes Promise.then, queueMicrotask, and setTimeout before you run it.
- Rewrite a loop of awaited calls with Promise.all, then state which results you lose when one call fails.
- Write a retry wrapper with a fixed attempt count and a growing delay, and confirm it stops after the last attempt.
- Cancel a fetch with AbortController and check that the promise rejects with an AbortError.
Key facts
- Tarmac has 11 JavaScript interview questions on this topic, 10 of them on this page, at difficulty 2–5 of 5.
- Tarmac tracked 1,180 job postings asking for JavaScript in November 2026.
- Roles asking for JavaScript advertise a median base salary of £72,250, across 456 job postings as of November 2026.
- Tarmac last reviewed these JavaScript interview questions on 23 November 2026.
At a glance
| Questions | 10 shown · 11 in the bank |
|---|---|
| Difficulty | 2–5 of 5 |
| Formats | True / false, Multiple answer, Flashcard, Find the bug, Coding exercise, Ordering |
| Interactive | 3 run your code against tests, in the app |
What you'll review
- async await
- promises
- promise combinators
- async error handling
Practice questions
Try one before you open the answer. Pick an option and press Check; it's marked on the spot.
An async function always returns a Promise, even if its body returns a plain value like return 5.#
Options
Show answer
True. An async function always wraps its result in a Promise. A plain return 5 resolves that returned Promise with 5, and throwing inside the function rejects it instead. To read the value out, you must await the call or attach a .then handler.
An async function wraps its result in a Promise. return 5 resolves the returned Promise with 5; throwing rejects it. To read the value you must await it or use .then.
Which statements about Promises are true?#
Options
Pick every one that applies.
Show answer
Three statements are true: a Promise can change from pending to fulfilled or rejected exactly once, .then() always returns a new Promise, and a .catch handles a rejection from anywhere earlier in the chain. A settled Promise cannot be reset to pending, and .then callbacks always run asynchronously as microtasks, never synchronously.
A Promise settles once and is then immutable (so 'a' is true, 'e' is false). .then/.catch always return a new Promise, enabling chaining ('b'), and a later .catch catches any earlier rejection ('c'). Reaction callbacks always run asynchronously as microtasks, never synchronously, so 'd' is false.
Promise.all([...]) rejects as soon as any input promise rejects, without waiting for the others to settle.#
Options
Show answer
True. Promise.all short-circuits on the first rejection, rejecting immediately with that reason rather than waiting for the rest. The other promises keep running, but their results are discarded. When you need every outcome regardless of failures, use Promise.allSettled instead.
Promise.all short-circuits on the first rejection and rejects immediately with that reason; the other promises keep running but their results are ignored. Use Promise.allSettled when you need every outcome regardless of failures.
How do you handle a rejected Promise when using await?#
Show answer
Wrap the await in a try/catch — a rejected awaited Promise throws inside the function, so catch receives the rejection reason. (Without try/catch, the rejection propagates out of the async function as a rejected Promise.)
await p on a rejected promise throws synchronously at that point, so ordinary try/catch works. Forgetting it lets the rejection surface as an unhandled rejection from the async function's returned promise.
This is meant to catch a failure from fetchData(), but the rejection escapes the try/catch as an unhandled rejection. What is the bug?#
async function load() {
try {
return fetchData();
} catch (err) {
console.error('failed', err);
}
}Options
Show answer
return fetchData() is not awaited, so the rejection settles outside the try
Returning a promise without await hands the still-pending promise to the caller; it rejects later, after the try block has already exited, so the catch never sees it. Use return await fetchData() so the rejection is thrown inside the try.
Contrast Promise.all, Promise.allSettled, Promise.race, and Promise.any.#
Show answer
all — fulfils with all results, rejects on the first rejection. allSettled — never rejects; fulfils with a status/value-or-reason for each. race — settles as the first promise to settle (fulfil OR reject). any — fulfils with the first fulfilment, rejects only if all reject (AggregateError).
all/any differ in failure handling (all-or-first-error vs first-success); race reacts to the first settlement of any kind; allSettled waits for everything and never short-circuits.
Implement async settleSummary(specs): each spec is { value, shouldReject }. Create one promise per spec — resolving with value, or rejecting with value when shouldReject is true — wait for ALL to settle, and return { fulfilled: [values in input order], rejected: count }.#
Starter code
async function settleSummary(specs) {
// TODO: settle every promise, never throw
return { fulfilled: [], rejected: 0 };
}Your solution must pass
- mixed outcomes
- all fulfilled
This one is written and run, not read. Solve it in the app and your code is executed against these tests and the hidden ones.
Implement retryWithBackoff(fn, maxAttempts, baseDelayMs, sleep): await fn(); when it rejects and attempts remain, await sleep(baseDelayMs * 2 ** (attempt - 1)) (attempt is 1-based, so the waits are base, base*2, base*4, …) and try again; after maxAttempts total attempts rethrow the LAST error. sleep is injected precisely so the tests need no real time — always wait through the provided sleep, never setTimeout. Write your implementation ABOVE the // ---- test driver (do not edit) ---- line; the runRetry driver builds a flaky fn, a fake sleep that logs its delay argument, and returns { outcome, attempts, delays }.#
Starter code
async function retryWithBackoff(fn, maxAttempts, baseDelayMs, sleep) {
// TODO: retry with exponential backoff, rethrow the last error
return fn();
}
// ---- test driver (do not edit) ----
async function runRetry(failTimes, maxAttempts, baseDelayMs) {
const delays = [];
let attempts = 0;
const fn = async () => {
attempts += 1;
if (attempts <= failTimes) throw new Error("boom " + attempts);
return "ok";
};
const sleep = (ms) => {
delays.push(ms);
return Promise.resolve();
};
let outcome;
try {
outcome = await retryWithBackoff(fn, maxAttempts, baseDelayMs, sleep);
} catch (error) {
outcome = error.message;
}
return { outcome, attempts, delays };
}Your solution must pass
- succeeds on the third attempt
- immediate success sleeps zero times
This one is written and run, not read. Solve it in the app and your code is executed against these tests and the hidden ones.
This runs top to bottom:#
Put these in order
Show answer
The logged order is:
ABCD
A logs first. Calling run() runs synchronously up to the await, logging B. The await then suspends and schedules the rest as a microtask, so control returns and C logs. Once the synchronous code finishes, the microtask resumes and logs D.
A logs first. Calling run() runs synchronously up to the await, logging B; await then suspends and schedules the rest as a microtask, so control returns and C logs. After the synchronous code finishes, the microtask resumes and logs D.
Implement mapLimit(items, limit, worker): map items through the async worker, running at most limit workers in flight at once, as an EAGER pool — start items in input order, and the moment any worker finishes, immediately start the next unstarted item. A sequential loop is wrong, and so is processing in fixed batches of limit (a batch waits for its slowest member; a pool does not). Resolve with the results in input order, regardless of completion order. Workers never reject. Write your implementation ABOVE the // ---- test driver (do not edit) ---- line; the runMapLimit driver holds each worker open behind a gate, releases the gates in a scripted order, and returns { results, maxActive, snapshots } — snapshots records which items had STARTED after the initial dispatch and again after each release, so it exposes both the pool's eagerness and its start order.#
Starter code
async function mapLimit(items, limit, worker) {
// TODO: run at most `limit` workers concurrently; results in input order
return [];
}
// ---- test driver (do not edit) ----
async function runMapLimit(items, limit, releaseOrder) {
const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
// Two macrotask ticks let every microtask cascade (and even a
// setTimeout-deferred pool step) finish before each snapshot.
const settle = async () => {
await tick();
await tick();
};
const gates = items.map(() => {
let open;
const opened = new Promise((resolve) => {
open = resolve;
});
return { opened, open };
});
const started = [];
let active = 0;
let maxActive = 0;
const worker = async (item) => {
started.push(item);
active += 1;
if (active > maxActive) maxActive = active;
await gates[items.indexOf(item)].opened;
active -= 1;
return item * 10;
};
const resultsPromise = mapLimit(items, limit, worker);
const snapshots = [];
await settle();
snapshots.push([...started]);
for (const index of releaseOrder) {
gates[index].open();
await settle();
snapshots.push([...started]);
}
const results = await resultsPromise;
return { results, maxActive, snapshots };
}Your solution must pass
- limit two refills the pool one item at a time
- limit one runs sequentially
This one is written and run, not read. Solve it in the app and your code is executed against these tests and the hidden ones.
Sources
The official documentation these questions are checked against:
Related interview questions
Job market
See javascript salaries and hiring demand from live job postings.
The other 1 question
This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 1 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.
Free · the whole bank · 100 answers per 30 days, each marked with written feedback