LuckyWinty / fe-weekly-questions

A pro to record some interview questions every week...
MIT License
341 stars 34 forks source link

在node11版本后,下面的代码输出是什么? #42

Open LuckyWinty opened 4 years ago

LuckyWinty commented 4 years ago
async function async1(){
    console.log('async1 start')
    await async2()
    console.log('async1 end')
  }
async function async2(){
    console.log('async2')
}
console.log('script start')
setTimeout(function(){
    console.log('setTimeout0') 
},0)  
setTimeout(function(){
    console.log('setTimeout3') 
},3)  
setImmediate(() => console.log('setImmediate'));
process.nextTick(() => console.log('nextTick'));
async1();
new Promise(function(resolve){
    console.log('promise1')
    resolve();
    console.log('promise2')
}).then(function(){
    console.log('promise3')
})
console.log('script end')
LuckyWinty commented 4 years ago
 //script start=>async1 start=>async2=>promise1=>promise2
//  =>script end=>nextTick=>async1 end=>promise3=>setTimeout0
// =>setImmediate=>setTimeout3