Let say we have the following snippet. Can someone explain what you expect to print out and why?
setTimeout(() => {
console.log("check 00");
}, 0);
new Promise((resolve, reject)=>{
console.log("check 01");
resolve();
}).then(()=>{
console.log("check 02");
})
console.log("check 03");
By running in the terminal, I got the following output.
check 01
check 03
check 02
check 00
I understand check 01
will be printed out first because Promise executor function is executed immediately by the Promise implementation. Then we have check 03
because of JS's run-to-completion scheduling.
But what about check 02
and check 00
?