Promise.then

then — A callback for a resolved Promise. Will execute as soon as the promise is resolved. If the promise is already resolved, it will execute instantly.

Description

Promise.then([mixed result])

Parameters

Name Description Type Default Optional
result The result from the resolve function in the promise. mixed Yes

Changelog

Version Description
ES 6 Introduced.

Examples

Example #1 – Nested example
new Promise(resolve => { resolve('resolved! :)'); }).then(result => { console.log(result); });
Example #2 – Hook example
let mypromise = new Promise(resolve => { resolve('resolved! :)'); }); mypromise.then(result => { console.log(result); });
Example #3 – Resolve after 1 second.
let mypromise = new Promise(resolve => { setTimeout(() => { resolve('resolved! :)'); }, 1000); }); mypromise.then(result => { console.log(result); }); console.log('Waiting…');
Example #4 – Bind hook 1 second after the promise has already been resolved
let mypromise = new Promise(resolve => { resolve('resolved! :)'); }); setTimeout(() => { mypromise.then(result => { console.log(result); }); }, 1000); console.log('Waiting…');

External references