前端面试题整理——关于EventLoop(1)

下面代码输出打印值顺序:

    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.cnblogs.com/MarsPGY/p/13460050.html