Day 91/100 JS中宏任务(setTimeout)和微任务(async await)的执行顺序的demo

(一)题目

async function async1() { console.log('async1 start') await async2() console.log('async1 end') setTimeout(() => { console.log('time1') }, 0) } async function async2() { console.log('async2 start') setTimeout(() => { console.log('time2') }, 0) } async1() console.log('start') setTimeout(() => { console.log('time3') }, 0)

(二)打印顺序
async1 start async2 start start async1 end time2 time3 time1

(三)分析 【Day 91/100 JS中宏任务(setTimeout)和微任务(async await)的执行顺序的demo】1、遇到await后面当前行的内容(无论语句还是函数方法);
2、遇到await后面非当前行的内容,是在函数执行后,才执行的;
3、宏任务队列中会按照push进去的先后顺序,依次打印输出;

    推荐阅读