then()
ES6+Attaches callbacks for the resolution and/or rejection of the Promise.
Syntax
promise.then(onFulfilled, onRejected)Parameters
onFulfilled Function A function called when the Promise is fulfilled
onRejected Function optionalA function called when the Promise is rejected
Return Value
Promise
A new Promise that resolves to the return value of the callback
Examples
JavaScript
const promise = Promise.resolve(42);
promise.then(value => {
console.log(value);
}); Output:
// 42