LuckyWinty / fe-weekly-questions

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

node中执行代码,求输出 #46

Open LuckyWinty opened 4 years ago

LuckyWinty commented 4 years ago
setImmediate(() => {
  console.log(1)
  setTimeout(() => {
    console.log(2)
  }, 100)
  setImmediate(() => {
    console.log(3)
  })
  process.nextTick(() => {
    console.log(4)
  })
})
process.nextTick(() => {
  console.log(5)
  setTimeout(() => {
    console.log(6)
  }, 100)
  setImmediate(() => {
    console.log(7)
  })
  process.nextTick(() => {
    console.log(8)
  })
})
console.log(9)
LuckyWinty commented 4 years ago

node11前:9->5->8->1->7->4->3->6->2 node11后:9->5->8->1->4->7->3->6->2