Code Example

Promise.resolve(1)
  .then(x => x + 1)
  .then(x => x * 2)
  .then(x => x + 1)
  .catch(err => console.error(err))
  .finally(() => console.log('Done'));

Promise Chain Visualization

Console Output

About Promise Chaining

Promises can be chained together to handle asynchronous operations sequentially. Each .then() returns a new promise, allowing you to chain multiple operations.

  • .then(): Executes when promise resolves
  • .catch(): Handles errors in the chain
  • .finally(): Executes regardless of success or failure

This visualization shows the step-by-step execution of a promise chain.