Recovery followed by a failing finally
Predict what reaches the last catch. What does returning from the first catch do?
Code Snippet
Promise.reject("initial")
.catch(reason => { console.log(reason); return "recovered"; })
.finally(() => { console.log("cleanup"); throw new Error("late"); })
.then(value => console.log(value))
.catch(error => console.log(error.message));Expected Output & Explanation
initial
cleanup
late The first catch recovers with a fulfillment. The finally callback then throws, replacing that outcome with a rejection. The intervening fulfillment handler is skipped.
Module Context & References
JavaScript · Async output drills Trace microtasks, promise identity, thenables and error recovery
Personal Notes · Markdown