Returning Values from .then()
What you'll learn: How returning a value from a .then() handler automatically wraps it in a resolved Promise for the next link in the chain.
The Magic of Return Values in Promise Chains
When you return a value from inside a .then() handler, JavaScript doesn't just pass that raw value to the next .then() — it wraps it in a new, resolved Promise. This automatic wrapping is what makes Promise chaining so elegant and powerful.
Think of it like a relay race where each runner (.then() handler) automatically packages their baton (return value) into a protective case (new Promise) before handing it off to the next runner.
How It Works
Promise.resolve(5)
.then(value => {
console.log(value); // 5
return value * 2; // Returns 10
})
.then(newValue => {
console.log(newValue); // 10 — received from previous .then()
return newValue + 3;
})
.then(finalValue => {
console.log(finalValue); // 13
});
Each return statement creates a new Promise that resolves with that value. Even though you write return 10, the next .then() actually receives Promise.resolve(10) behind the scenes.
Why This Matters
This automatic wrapping means:
- You can chain operations cleanly without manual Promise creation
- Each step waits for the previous Promise to settle
- You write synchronous-looking code that behaves asynchronously
- The chain continues smoothly from one handler to the next
If you don't return anything, the next .then() receives undefined (wrapped in a resolved Promise).
Key Takeaway: Returning a value from .then() automatically wraps it in a resolved Promise, letting you chain operations naturally while maintaining asynchronous flow control.