Promise输出顺序

话不多说先看题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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,2,4,3,5,6。 复制到浏览器里查看结果,发现不对。浏览器输出的结果为 0,1,2,3,4,5,6