Skip to content

输出什么?

Posted on:2021年7月3日 at 22:31
const myPromise = Promise.resolve("Woah some cool data");

(async () => {
  try {
    console.log(await myPromise);
  } catch {
    throw new Error(`Oops didn't work`);
  } finally {
    console.log("Oh finally!");
  }
})();

try 块区,我们打印 myPromise 变量的 awaited 值: "Woah some cool data"。因为try 块区没有错误抛出,catch 块区的代码并不执行。finally 块区的代码 总是 执行,"Oh finally!" 被输出。

原文转自:https://fe.ecool.fun/topic/6a5130e7-9c13-4dce-9ab5-07ace7597d59