面试题经常会有
<script>console.log(1)setTimeout(function(){console.log(2)})console.log(3)let p=new Promise((resolve,reject) =>{console.log(4)resloved('hhhhhh')})p.then(res =>{console.log(res)console.log(5)},res =>{console.log(7)})console.log(6)</script>
宏任务:script(整体代码),setTimeout,UI渲染,VO,postMessage,MessageChannel,setlmmedate(node环境)
微任务:Promise, MultationObserver, proxess.nextTick(node环境)
执行顺序
1
3
4
6
hhhhhh
5
2
注意: Promise ,一旦创建立即执行,打印7是迷惑项不会执行