It returns as soon as the first promise settles (fulfilled or rejected). If the first to settle fulfills, the race fulfills with its value. If the first to settle rejects, the race rejects with its reason.
What does Promise.race do in JavaScript?
More FAQs in Promise.race: Examples and Use Cases in JavaScript
Race the operation against a timeout promise: Promise.race([fetch('/api'), new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 5000))]). If the timeout fires first, the race rejects.
Yes. If the first promise to settle rejects, the race rejects with that reason. This is different from Promise.any, which ignores rejections and waits for the first fulfillment.
It never settles (stays pending forever). Be careful not to pass an empty array to Promise.race. If you dynamically build the array, check that it is not empty.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.