AceDevHub
Intermediate JavaScript Interview QuestionsIntermediateConcept

JavaScript · Question 47

How does Promise chaining propagate returned values, returned Promises, and thrown errors?

Direct answer

Each then/catch call returns a new Promise: a returned normal value fulfills the next Promise, a returned Promise/thenable is adopted, and a thrown exception rejects the next Promise.

Promise chains are composable because then() does not mutate and return the same Promise. It creates a new Promise whose outcome depends on the handler result.

  • return 42 from a fulfillment handler → the next then receives 42.
  • return fetch(url) → the chain waits for that returned Promise instead of nesting a Promise as a plain value.
  • throw new Error('x') → the new Promise is rejected and control jumps to the next matching rejection handler.
  • If a handler is omitted, fulfillment values or rejection reasons pass through to later links.

A common bug is starting asynchronous work inside then() without returning it. The outer chain then cannot wait for that work or reliably propagate its failure.