下面代碼輸出列印值順序:
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')
考點:
JS中EventLoop的運行機制,
宏任務和微任務的執行順序,(微任務先執行,宏任務后執行)
哪些任務屬于宏任務,哪些任務屬于微任務:
宏任務:
I/O、setTimeout、setInterval、setImmediate、requestAnimationFrame
微任務:
process.nextTick、MutationObserver、Promise.then catch finally
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/11176.html
標籤:JavaScript
