Skip to content

【Promise第40题】下面代码的输出是什么?

Posted on:2024年7月20日 at 11:01
const p1 = new Promise((resolve) => {
  setTimeout(() => {
    resolve("resolve3");
    console.log("timer1");
  }, 0);
  resolve("resovle1");
  resolve("resolve2");
})
  .then((res) => {
    console.log(res);
    setTimeout(() => {
      console.log(p1);
    }, 1000);
  })
  .finally((res) => {
    console.log("finally", res);
  });

解析

结果

'resolve1'
'finally' undefined
'timer1'
Promise{<resolved>: undefined}

原文转自:https://fe.ecool.fun/topic/dec780c4-3610-4673-b12f-add388ceec10