Async & promises · Output question
JavaScript promise chains and returned values
A promise reaction transforms a value and returns it. Predict which value the next reaction receives.
Promise.resolve(3)
.then(value => value + 2)
.then(value => { console.log(value); })
.then(value => console.log(value));What gets logged?
Choose an output before opening the walkthrough, or check your answer in practice mode.
Reveal the answer and execution trace
5
undefinedThe first callback returns 5. The next callback logs 5 and returns nothing, so its resulting promise fulfills with undefined.
- Line 2. Returning value + 2 fulfills the next promise with 5.
- Line 3. This block logs 5, then implicitly returns undefined.
- Line 4. The final callback receives undefined.
Reference: Promise chain values on MDN.