菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
187
0

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

原创
05/13 14:22
阅读数 99888

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

    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

发表评论

0/200
187 点赞
0 评论
收藏
为你推荐 换一批