Interview Q&A / JavaScript

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What is the difference between Promise.all, allSettled, race and any?

SHORT ANSWER

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.

Explain it simply

Think of four ways to book tickets on several apps at once.

  • all: "I need every booking to work." Result: an array of values in the original order. One failure rejects the whole thing immediately.
  • allSettled: "Tell me what happened with each." Never rejects; gives {status, value | reason} for each.
  • race: "Whoever answers first, success or failure, decides."
  • any: "First success wins." It rejects with an AggregateError only if every promise fails.

Use all for dependent data, allSettled for independent jobs where you want a report, race for timeouts, and any for fallback mirrors.

Example

js
const ok = (v, ms) => new Promise((r) => setTimeout(() => r(v), ms));
const bad = (ms) => new Promise((_, rej) => setTimeout(() => rej(new Error("fail")), ms));

Promise.all([ok("a", 10), ok("b", 20)])
  .then((r) => console.log(r.join()));              // -> a,b
Promise.all([ok("a", 10), bad(5)])
  .catch((e) => console.log(e.message));            // -> fail
Promise.allSettled([ok("a", 10), bad(5)])
  .then((r) => console.log(r.map((x) => x.status).join())); // -> fulfilled,rejected
Promise.race([ok("slow", 50), ok("fast", 10)])
  .then(console.log);                               // -> fast
Promise.any([bad(5), ok("win", 20)])
  .then(console.log);                               // -> win

What to say in the interview

"all fails fast on any rejection and keeps result order; allSettled always waits and reports every outcome; race takes the first settled promise, good for timeouts; any takes the first fulfilled one and only rejects with an AggregateError when all reject."

Common mistakes

  • Using Promise.all for independent tasks and losing every result because one failed.
  • Forgetting that race can resolve with a rejection.

#javascript#promises#async

Related questions

Practise more JavaScript questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open JavaScript quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.