What is the difference between Promise.any and Promise.race in JavaScript?
Promise.race returns the first to settle (fulfilled or rejected). Promise.any returns the first to fulfill (ignores rejections). race can reject on the first rejection; any only rejects if all reject (with AggregateError).
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Promise.any: Examples and Use Cases in JavaScript
It returns as soon as the first promise fulfills. It ignores rejections until all promises reject. If all reject, it rejects with an AggregateError containing all the rejection reasons.
An error type thrown by Promise.any when all promises reject. It has an errors property (an array of all individual rejection reasons). Check err instanceof AggregateError and access err.errors.
It rejects with an AggregateError (all promises reject, and there are no promises to fulfill). This is different from Promise.race([]), which never settles.
Still have questions?
Browse all our FAQs or reach out to our support team
