Promise Chaining in JavaScript
Level 4148 keystrokes
Promise chaining allows sequential asynchronous operations by returning values from then().
JavaScript code
// Promise.resolve(1) creates a resolved promise with value 11Promise.resolve(1) // First then: 1 + 1 = 22 .then(x => x + 1) // Second then: 2 * 2 = 43 .then(x => x * 2) // Third then: log the result4 .then(x => console.log(x));// Another chain starting with 10 (it has fewer then steps, so 15 is printed before 4)5Promise.resolve(10) // 10 + 5 = 156 .then(x => x + 5) // Log 157 .then(x => console.log(x));Output
15 4
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
.× 9(× 9)× 9=× 5>× 5;× 2+× 2*× 1