异步和同步
Visionwuwu 2020-05-31
javascript
# 面试题
js是门单线程语言,先执行主栈任务,再执行异步任务。本题考查宏任务和微任务,事件队列,事件循环机制。
async function async1(){
console.log('async1 start')
await async2()
console.log('async1 end')
}
function async2(){
console.log('async2')
}
console.log('script start')
setTimeout(_=>{
console.log('setTimeOut')
},0)
async1()
new Promise(resolve=>{
console.log('Promise1')
resolve()
}).then(res=>{
console.log('Promise2')
})
console.log('script end')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
解析
