Allows you to specify work to be done on the fulfillment of a promise.
Syntax
promise.then(onCompleted, onRejected);
Parameters
promise
Required. The promise object.
onCompleted
Required. The fulfillment handler function to run when the promise completes successfully.
onRejected
Optional. The error handler function to run when the promise is rejected.
Remarks
A Promise must either be completed with a value, or it must be rejected with a reason. The then method of the Promise object runs when the promise is completed or rejected, whichever occurs first. If the promise is completed successfully, the fulfillment handler function of the then method runs. If the promise is rejected, the error handler function of the then method (or the catch method) runs.
Example
The following example shows how to call a function (timeout) that returns a promise. The fulfillment handler of the then method runs after the 5000ms timeout period expires.
function timeout(duration) {
return new Promise(function(resolve, reject) {
setTimeout(resolve, duration);
});
}
// Note: This code uses arrow function syntax
var m = timeout(5000).then(() => {
console.log("done!");
})
// Output (after 5 seconds):
// done!
Requirements
Supported in Microsoft Edge (Edge browser). Also supported in Store apps (Microsoft Edge on Windows 10). See Version Information.
Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Not supported in Windows 8.1.

