JavaScript · Middle · Question 19 of 75
How does Promise.any differ from Promise.race?
- ✓Correct answer:
anywaits for the first success,racefor the first settled with any outcome - 2
racewaits for the first success, whileanywaits for the first settled with any outcome - 3They're synonyms;
anyis the newer name ofrace
Explanation
Promise.any rejects only if all of them reject, with an AggregateError. Promise.race adopts the outcome of the fastest - that's how timeouts are done: Promise.race([fetch(url), timeout(5000)]).