背景
一天惬意的下午。朋友给我分享了一道头条面试题,如下:
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('setTimeout')
},0)
async1();
new Promise(function(resolve){
console.log('promise1')
resolve();
}).then(function(){
console.log('promise2')
})
console.log('script end')
这个题目主要是考察对同步任务、异步任务:setTimeout、promise、async/await的执行顺序的理解程度。(建议大家也自己先做一下o)
当时由于我对async、await了解的不是很清楚,答案错的千奇百怪
标签:resolve,console,进阶,队列,macro,js,任务,Promise,log From: https://www.cnblogs.com/loveX001/p/16749947.html