Skip to content

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

Posted on:2024年7月20日 at 11:01
function promise1() {
  let p = new Promise((resolve) => {
    console.log("promise1");
    resolve("1");
  });
  return p;
}
function promise2() {
  return new Promise((resolve, reject) => {
    reject("error");
  });
}
promise1()
  .then((res) => console.log(res))
  .catch((err) => console.log(err))
  .finally(() => console.log("finally1"));

promise2()
  .then((res) => console.log(res))
  .catch((err) => console.log(err))
  .finally(() => console.log("finally2"));

执行过程

结果

'promise1'
'1'
'error'
'finally1'
'finally2'
原文转自:https://fe.ecool.fun/topic/fa9e9946-de5b-4998-a224-8d512d3ccac2