图文并茂了解event loop执行

696 阅读1分钟

event概念就不细讲了;只看面试题;啊~知识分享真的太难了;佩服掘金博客大神,感谢他们的分享

async function f1() {
  console.log(1)
  await f2()
  console.log(2)
}
async function f2() {
  console.log(3)
}
console.log(4)
setTimeout(() => {
  console.log(5)
}, 0)

f1()
new Promise(function (resolve, reject) {
  console.log(6)
  resolve()
}).then(function () {
  console.log(7)
})
console.log(8)

看上述代码,请输入打印顺序;

eventLoop.png

eventLoop1.png

eventLoop2.png

eventLoop3.png

eventLoop4.png

eventLoop5.png

eventLoop6.png

eventLoop7.png

eventLoop8.png

eventLoop9.png

eventLoop10.png

eventLoop11.png

eventLoop12.png

eventLoop13.png

eventLoop14.png

eventLoop15.png

eventLoop16.png

eventLoop17.png