首页 > 解决方案 > 关于Promise,这个问题让我很困惑

问题描述

这是代码:

Promise.resolve().then(() => {
    console.log(0);
    return Promise.resolve(4);
}).then((res) => {
    console.log(res)
})
            
Promise.resolve().then(() => {
    console.log(1);
}).then(() => {
    console.log(2);
}).then(() => {
    console.log(3);
}).then(() => {
    console.log(5);
}).then(() => {
    console.log(6);
})

对我来说,我以为答案是 0;1;4;2;3;5;6。但结果不是。为什么?

标签: promise

解决方案


推荐阅读