第一次面试,就挂在了 异步执行顺序上,setTimeout async/await promise的执行顺序,搞不清楚,看了许多博客,但在关键点不是很详细。
可以先看一下大佬的解释: 网页链接
async function async1() {
console.log('async1 start')
await async2()
console.log('async1 end')
}
async function async2() {
console.log('async2')
}
console.log('script start')
setTimeout(() => {
console.log('setTimeout')
},0)
async1()
new Promise((resolve) => {
console.log('promise1')
resolve()
}).then(() => {
console.log('promise2')
}