In this document: MDN - Promise() constructor
there is a phrase:
- The operation within executor is asynchronous and provides a callback.
And here is code
console.log('before promise');
new Promise(function(resolve, reject) {
console.log('promise');
let j = 0;
for (i = 0; i < 1000000000; i++) {
j++;
}
resolve(1);
console.log('promise end');
}).then(function() {
console.log('then');
});
console.log('not promise but after');
It displays in console
- before promise
- promise
- promise end
- not promise but after
- then
I thought once operation within executor is asynchronous, then Javascript should not wait for finish of code within executor , and "not promise but after" should be displayed right after "before promise". But it seems i do not understand meaning of this phrase. Can please someone explain what does it mean?