Handlers
Learn about the assignment of handlers.
We'll cover the following...
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.
Both arguments to then()
are optional, so we can listen for any combination of fulfillment and rejection. For example, consider this set of then()
calls: ...