-
-
微任務 遇到微任務,放在當前任務列的最底端(then或者catch里面的內容)
-
-
宏任務 setTimeout setInterval
-
宏任務 遇到宏任務,放到下一個新增任務列的最頂端
-
-
當前任務列執行完成了再去執行下一個任務列
-
當then和then的外層都有宏任務時,先創建外層的宏任務
Promise.resolve().then(function () { console.log(1); Promise.resolve().then(function () { console.log(2); }); Promise.resolve().then(function(){ console.log(3); }); }); Promise.resolve().then(function(){ console.log(4); })//1423 async function fn(){ console.log(1); await Promise.resolve().then(function(){ console.log(2); }) await Promise.resolve().then(function(){ return 3; }); await Promise.resolve().then(function(){ console.log(4); }) } fn().then(function(num){ console.log(num); })//124underfined console.log(0); setTimeout(console.log(1),0);//這個里面執行的是代碼塊不是語句塊,直接執行就OK了 console.log(2); //012