Assigning handlers with then()

The then() method is present on all promises and takes two arguments. The first argument is a function to call when the promise is fulfilled, called the fulfillment handler. Any additional data related to the asynchronous operation is passed to this function.

The second argument is a function to call when the promise is rejected, called the rejection handler. Similar to the fulfillment handler, the rejection handler is passed any additional data related to the rejection.

Note: Any object that implements the then() method in this way is called a thenable. All promises are thenables, but not all thenables are promises.

Let’s understand this with the following illustration.

Get hands-on with 1200+ tech skills courses.