Member-only story
Analysis
This question is actually examining the execution order of the code. To be precise, it is examining the difference between asynchronous functions such as setTimeout, Promise, and async/await.
Let’s look at the simplest case first:
console.log('111')console.log('222')
What is the execution result of this code? Anyone who has studied programming knows that the program will output 111
and 222
in sequence. There is no asynchronous code in this code, so it is very simple.
Let’s look at another example:
console.log('111')setTimeout(() => {
console.log('333')
}, 0)console.log('222')