0
点赞
收藏
分享

微信扫一扫

promise和setTimeout async/await顺序面试题

前程有光 2021-09-30 阅读 40
web 前端
async function async1(){
    console.log('async1 start')//2
    await async2() //await后面都作为回调内容 微任务1=>放在微任务队列
    console.log('async1 end') 
}
async function async2() {
    console.log('async2')//3
}
console.log('script start')//1

setTimeout(() => { //宏任务 setTimeout =>callback queue
    console.log('setTimeout')
});

async1()//

//初始化Promise是,传入的函数会立刻被执行
new Promise((resolve=>{
    console.log('promise1')//4
    resolve()
})).then(function () { //微任务2=>放在微任务队列
    console.log('promise2')
})
console.log('script end')//5

结果:

举报

相关推荐

0 条评论