It is said that the callback (called executor) that executes the constructor new Promise() is always executed synchronously, therefore, the following question arises:
- The executor is called synchronously (as soon as the Promise is constructed) with the
resolveFuncandrejectFuncfunctions 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.