Is the promise returned by new Promise() resolved or rejected synchronously as soon as the executor is executed?

121 Views Asked by At

It is said that the callback (called executor) that executes the constructor new Promise() is always executed synchronously, therefore, the following question arises:

  1. The executor is called synchronously (as soon as the Promise is constructed) with the resolveFunc and rejectFunc functions as arguments.

Is the promise returned by new Promise() also resolved or rejected synchronously as soon as the executor is executed?

const myPromise = new Promise((resolve, reject) => {
  if (/* some condition */) {
    resolve('Promise fulfilled');
  } else {
    reject('Promise rejected');
  }
});

// The promise has been created and its fate (resolved or rejected) is now determined.
// But we can only see its status when JavaScript has completed the execution of the current code and has emptied the callstack

I don't want to do something concrete, I just want to evaluate my knowledge.

0

There are 0 best solutions below