---
title: "What is the purpose of the then method in Promises? How does it work?"  
description: "What is the purpose of the then method in Promises? How does it work?"  
author: "Sandra Emily"  
published: 2023-09-26  
updated: 2023-09-26  
canonical: https://www.mindstick.com/forum/159916/what-is-the-purpose-of-the-then-method-in-promises-how-does-it-work  
category: "javascript"  
tags: ["javascript", "promise"]  
reading_time: 3 minutes  

---

# What is the purpose of the then method in Promises? How does it work?

What is the [purpose](https://yourviews.mindstick.com/view/247/no-fail-policy-failing-its-purpose) of the **then** [method](https://www.mindstick.com/forum/166/webservice-method) in [Promises](https://www.mindstick.com/forum/160100/how-do-promises-in-javascript-simplify-asynchronous-code-compared-to-callbacks)? How does it work?

## Replies

### Reply by Aryan Kumar

The **then()** method in Promises serves two primary purposes:

**Handling the Success of a Promise**:

- The main purpose of the **then()** method is to specify a callback function that will be executed when the Promise is resolved successfully (i.e., when it transitions to the fulfilled state).
- This callback function receives the resolved value of the Promise as its argument, allowing you to work with the result of the asynchronous operation.

**Chaining Promises**:

- Another key purpose of **then()** is to facilitate chaining Promises together, enabling you to sequence multiple asynchronous operations in a clean and organized manner.
- When you return a new Promise (or any value) from the **then()** callback, it creates a new Promise that represents the result of the callback function. This allows you to chain Promises one after the other.

Here's how the **then()** method works:

You call **then()** on a Promise object and provide one or two callback functions:

- The first callback function is executed when the Promise is resolved successfully. It takes one argument, which is the resolved value of the Promise.
- The second callback function is optional and is executed when the Promise is rejected. It takes one argument, which is the rejection reason.

The **then()** method returns a new Promise. This new Promise will be in one of the following states, depending on what happens in the callback function:

- If the callback function returns a value, the new Promise will be resolved with that value.
- If the callback function throws an exception or returns a rejected Promise, the new Promise will be rejected with the exception or rejection reason.

Here's an example illustrating how **then()** works for handling success:

```plaintext
const myPromise = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve("Operation succeeded!");
  }, 1000);
});

myPromise.then((result) => {
  console.log("Success:", result);
});
```

In this example, when **myPromise** is resolved successfully, the callback function provided to **.then()** is executed with the resolved value, allowing you to handle the success of the asynchronous operation.

And here's an example demonstrating chaining Promises:

```plaintext
const firstAsyncOperation = () => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(1);
    }, 1000);
  });
};

const secondAsyncOperation = (value) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(value + 2);
    }, 1000);
  });
};

firstAsyncOperation()
  .then((result) => {
    console.log("First operation result:", result);
    return secondAsyncOperation(result);
  })
  .then((result) => {
    console.log("Second operation result:", result);
  });
```

In this chained example, the **then()** method is used to chain two asynchronous operations together, ensuring that the second operation waits for the first one to complete before executing.


---

Original Source: https://www.mindstick.com/forum/159916/what-is-the-purpose-of-the-then-method-in-promises-how-does-it-work

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
