Skip to content

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

Posted on:2024年7月20日 at 11:01
const promise = new Promise((resolve, reject) => {
  console.log(1);
  setTimeout(() => {
    console.log("timerStart");
    resolve("success");
    console.log("timerEnd");
  }, 0);
  console.log(2);
});
promise.then((res) => {
  console.log(res);
});
console.log(4);

解析

结果

1
2
4
"timerStart"
"timerEnd"
"success"
原文转自:https://fe.ecool.fun/topic/a7ccbacc-5415-4c3f-b168-5fcc4d7792ee