Promise.prototype.then

Attaches callback functions for the resolution and/or rejection of the promise.

Syntax

then(onfulfilled?, onrejected?)

Parameters

Return value

A promise for the completion of which ever callback is executed.

Examples

let p = new Promise((resolve, reject) => {
  resolve("hello")
})
p.then(value => print(value))
hello

let p = new Promise((resolve, reject) => {
  reject(new Error("something happened"))
})
p.then(value => print('resolved:', value), error => print('rejected:', error.message))
rejected: something happened