Predict Promise.then Chain
Predict Output Medium
Question
What does this code print?
Code
Promise.resolve(5)
.then(x => x + 3)
.then(x => x * 2)
.then(x => console.log(x));
Hint
Each then receives the result of the previous one.
Explanation
The chain starts with Promise.resolve(5). First .then: 5 + 3 = 8. Second .then: 8 * 2 = 16. Third .then: console.log(16) prints 16. Each .then receives the resolved value from the previous step and passes its return value to the next.
Related Resources
Related Lessons
- Async JavaScript
Learn about Promise chains.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.