Promise Chaining in JavaScript

Javascript 9 min min read Updated: Mar 09, 2026 Intermediate
Promise Chaining in JavaScript
Intermediate Topic 8 of 15

In JavaScript, promises allow developers to handle asynchronous operations efficiently. Often, multiple asynchronous tasks need to run in sequence, where the result of one task is used in the next. To handle such situations, JavaScript provides a concept called Promise Chaining.

Promise chaining allows multiple then() methods to be linked together so that asynchronous tasks can run one after another in a structured and readable way.

What is Promise Chaining?

Promise chaining is a technique where multiple asynchronous operations are connected using the then() method. Each then() receives the result from the previous promise and returns a new promise.

Key Point: Promise chaining allows multiple asynchronous tasks to run sequentially without deeply nested callbacks.

Basic Example of Promise Chaining

javascript let promise = new Promise(function(resolve){ resolve(5); }); promise .then(function(result){ console.log(result); return result * 2; }) .then(function(result){ console.log(result); return result * 2; }) .then(function(result){ console.log(result); });
Output

5

10

20

In this example, each then() receives the result from the previous step and passes a new value to the next promise in the chain.

Promise Chaining with Asynchronous Tasks

Promise chaining becomes especially useful when working with asynchronous operations such as API calls or timers.

javascript function stepOne(){ return new Promise(function(resolve){ setTimeout(function(){ resolve("Step 1 completed"); },1000); }); } stepOne() .then(function(result){ console.log(result); return "Step 2 completed"; }) .then(function(result){ console.log(result); return "Step 3 completed"; }) .then(function(result){ console.log(result); });
Output

Step 1 completed

Step 2 completed

Step 3 completed

Key Point: Each then() returns a new promise that can be used in the next step.

Error Handling in Promise Chains

Errors that occur in any part of the promise chain can be handled using the catch() method.

javascript let promise = new Promise(function(resolve, reject){ reject("Something went wrong"); }); promise .then(function(result){ console.log(result); }) .catch(function(error){ console.log(error); });
Output

Something went wrong

Advantages of Promise Chaining

  • Reduces nested callbacks
  • Makes asynchronous code easier to read
  • Improves code organization
  • Allows sequential execution of asynchronous tasks

Conclusion

Promise chaining is an important technique in JavaScript for managing multiple asynchronous operations. By linking promises using the then() method, developers can write cleaner and more structured asynchronous code.

This approach makes JavaScript programs easier to maintain and helps avoid complex nested callback structures.

In the next tutorial, you will learn about Promise.all() and Promise.race(), which allow developers to manage multiple promises running at the same time.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators