Do you know what will be the output of this code?
JavaScript
async function fail() {
throw new Error("oops");
}
try {
fail();
console.log("no error");
} catch (e) {
console.log("caught");
}
Show answer and explanation
The answer is "no error".
fail() doesn’t throw. It returns a rejected promise. The try block finishes normally, and the rejection is unhandled. Use await fail() inside an async function so catch can see it.