What does finally do with return values and errors in this code?
async function main() {
const a = await Promise.resolve("value").finally(() => "ignored");
console.log(a);
const b = await Promise.reject(new Error("original"))
.finally(() => console.log("cleanup"))
.catch((error) => error.message);
console.log(b);
const c = await Promise.resolve("value")
.finally(() => {
throw new Error("from finally");
})
.catch((error) => error.message);
console.log(c);
}
main();
The answer
Work out every line it logs, in order. Then check.
Checking your sign-in…