Interview Question

What is promise chaining?

Each promise handler determines the state of the next promise in the chain.

💡 Concept ✅ Quick Revision ⚡ JavaScript

Answer

Promise chaining connects asynchronous steps through promises returned by then or catch. • Each then call returns a distinct promise. • A returned value fulfills the next promise. • A thrown error or rejected returned promise rejects the next promise.

Example

Code
Promise.resolve(2)
  .then(value => value + 1)
  .then(value => value * 4)
  .then(console.log);
Output
12

Quick Revision

Each promise handler determines the state of the next promise in the chain.