- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Promise Chaining
JavaScript Asynchronous
JavaScript Promise Chaining
Returning a value from
thenpasses it to the nextthenin the chain.
Each then returns a new promise, which is what makes chaining possible.
This is how promises replace deeply nested callbacks with a flat sequence.
Example
Example
javascript
Promise.resolve(2)
.then(function (n) {
return n * 5;
})
.then(function (n) {
console.log(n);
});