console 立即输出 调试_小米二面:Promise链输出顺序

本文详细解析了Promise链式调用中输出顺序的理解,重点介绍了new Promise的状态变化、then回调的执行时机以及微任务队列的工作原理。通过一个面试题目,解释了为何在理解Promise的'立即'特性后,可以正确预测和调试相关输出。
摘要由CSDN通过智能技术生成
new Promise((resolve, reject) => {
        console.log('外部promise')    resolve()})    .then(() => { //then1        console.log('外部第一个then')        new Promise((resolve, reject) => {
                console.log('内部promise')            resolve()        })            .then(() => { //then2                console.log('内部第一个then')            })            .then(() => { //then3                console.log('内部第二个then')            })    })    .then(() => {  //then4        console.log('外部第二个then')    })    .then(() => {  //then5        console.log('外部第三个then')    })    .then(() => {  //then6        console.log('外部第四个then')    })

这是上周小米二面的时候面试官出的一道读代码题,当时写到一半的时候面试官就说不对然后给了一些提示,然而还是没有回答出来...在面试结束之后自己做了个断点调试,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值