JS Daily 33 - Multiple Resolve in Promises

Published on 23 Dec, 2020

What is the output of following code?

const p1 = new Promise((resolve, reject) => {
  resolve();
  resolve();
  resolve();
});

p1.then(() => {
  console.log("Resolved");
});
----o----

The output is:

"Resolved"

Even though resolve() is called 3 times, the code will be resolved only once. That is how promises work.

Same is the case with reject(). Even if the code is rejected multiple times, .catch() will be called only once.