Thursday, September 4, 2025
HomeLanguagesJavascriptJavaScript Promise race() Method

JavaScript Promise race() Method

The Promise.race() method returns a promise that fulfills or rejects as soon as one of the promises in an iterable fulfills or rejects, with the value or reason from that promise.

We may think of this particular method as in the form of a real-life example where several people are running in a race whosoever wins comes first wins the race, the same scenario is here, which ever promise is successfully fulfills or rejects at early will be executed at first and rest one’s results will not be displayed as an output.

Syntax:

Promise.race(iterable);

Parameters:

  • iterable: An iterable object such as Array, Map, String, etc. having several different promises in them.

Example 1: This example shows the basic use of the Promise.race() method in Javascript. As promise2 was faster so it prints its own result which is two.

Javascript




const promise1 = new Promise((resolve, reject) => {
    setTimeout(resolve, 600, "one");
});
 
const promise2 = new Promise((resolve, reject) => {
    setTimeout(resolve, 200, "two");
});
 
Promise.race([promise1, promise2]).then((value) => {
    console.log(value);
});


Output

two

Example 2: This example shows the basic use of the Promise.race() method in Javascript. As promise2 is faster than promise1, so it rejects and doesn’t print anything.

Javascript




const promise1 = new Promise((resolve, reject) => {
    setTimeout(() => resolve("five"), 500);
});
 
const promise2 = new Promise((resolve, reject) => {
    setTimeout(() => reject(new Error("six")), 100);
});
 
Promise.race([promise1, promise2]).then((value) => {
    console.log(value);
});


Output: 

Uncaught (in promise) Error: six

We have a complete list of Javascript Promise Methods, to check those please go through the Javascript Promise Complete Reference article.

Supported Browsers: 

  • Google Chrome 32 and above
  • Edge 12 and above
  • Mozilla Firefox 29 and above
  • Opera 19 and above
  • Safari 8 and above
  • Internet Explorer not supported
RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS