⊗jsSpPrmPICh 168 of 281 menu

Promises within a chain in JavaScript

Functions within a chain can also return promises. In this case, the result of this promise will fall into the next then:

promise.then( function(result) { return result + '1'; } ).then( function(result) { return new Promise(function(resolve) { resolve(result + '2'); // this result will fall into the next then }); } ).then( function(result) { return result + '3'; } ).then( function(result) { console.log(result); // shows 'string123' } );
enru