浏览器宏任务和微任务
开始
async function async1 () {
console.log('async1 start')
await async2()
console.log('async1 end')
}
async function async2 () {
console.log('async2')
setTimeout(() => {
console.log('async2 setTimeout')
},0)
}
console.log('script start')
async1()
setTimeout(() => {
console.log('setTimeout')
},0)
new Promise((resolve) => {
console.log('promise1')
resolve()
}).then(() => {
console.log('promise2')
})
console.log('script end')思考
宏任务和微任务
浏览器的执行顺序
实际执行的代码结构
结果
参考
Last updated
Was this helpful?