Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Promise Object</h1>
<h2>The race() Metod</h2>
<p id="demo"></p>
<script>
// Create a Promise
const myPromise1 = new Promise((resolve, reject) => {
  setTimeout(resolve, 200, "King");
});
// Create another Promise
const myPromise2 = new Promise((resolve, reject) => {
  setTimeout(resolve, 100, "Queen");
});
// Both resolves. Who is faster?
Promise.race([myPromise1, myPromise2]).then((x) => {
  myDisplay(x);
});
// Funtion to run when a Promise is settled:
function myDisplay(some) {
  document.getElementById("demo").innerHTML = some;
}
</script>
</body>
</html>