JavaScript · Promises · Mid-Level · Comparison
Compare `Promise.all`, `Promise.allSettled`, `Promise.race`, and `Promise.any`.
Short Interview Answer
`all` fulfills when all fulfill (fails fast); `allSettled` waits for all outcomes; `race` settles with the first settle; `any` fulfills with first fulfill (AggregateError if all reject).
Detailed Explanation
Use `all` for dependent parallel success. Use `allSettled` when you need every result including failures (dashboards). Use `race` for timeouts (`race([fetch, timeoutPromise])`) or first-done wins. Use `any` when any success is enough among mirrors. Know that `all`/`race` short-circuit differently. For large sets, consider concurrency limits instead of unbounded `all`.
Example
const result = await Promise.allSettled([p1, p2]);
// [{status:'fulfilled', value}, {status:'rejected', reason}]Interview Tip
Give a one-line use case for each.
Common Mistake
Using `race` for 'first success' when `any` is intended.