cf.completefrontend

Predict the outputHard

What does this log, and why does only one of these try/catch blocks catch the rejection?

What does this log?
async function fail() {
  throw new Error("nope");
}
 
async function withoutAwait() {
  try {
    return fail();
  } catch {
    return "caught in withoutAwait";
  }
}
 
async function withAwait() {
  try {
    return await fail();
  } catch {
    return "caught in withAwait";
  }
}
 
async function main() {
  console.log(await withAwait());
  try {
    console.log(await withoutAwait());
  } catch (error) {
    console.log("main caught:", error.message);
  }
}
 
main();

The answer

Work out every line it logs, in order. Then check.

Checking your sign-in…