![]() |
JavaScript Promise then() method is called whenever a promise is resolved. It takes data from the resolved promise. It can take up to two arguments which are callback functions for the fulfilled and rejected cases respectively. Just like the catch() method it also returns a Promise so it is used to chain Promises. Syntax: then(successFunc, rejectFunc) Parameter: It usually takes up to two parameters and the second parameter is optional. These parameters receive data from the Promise
Return Value: This method returns a promise which is in the pending state even if the previous promise is finished. Example 1: This example uses the then method to handle the resolve state of a promise. Javascript
Output: Hello Successful Example 2: This example uses then method to handle reject of a Promise by passing the second argument. Javascript
Output: Rejected Example 3: This example uses then method to chain promises. Javascript
Output: The first then returns Promise which is handled by the second then block Successful Completed Supported Browsers:
We have a complete list of Javascript Promise methods, to check those please go through the Javascript Promise Reference article |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |