Passing value into next Promises argument
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In a promise chain, the value for the next .then(...) callback comes from what the previous handler returns. You do not manually push a value into the next promise as a separate step. You either return a plain value, return another promise, or throw an error, and the chain updates itself accordingly.
The Core Rule Of .then()
A promise callback receives the previous fulfillment value. Its return value becomes the fulfillment value of the next link in the chain.
Output:
The second .then(...) gets 10 because the first handler returned value * 2.
Returning A Plain Value Versus A Promise
If you return a plain value, the next promise resolves with that value.
If you return a promise, the next step waits for that promise to resolve.
This is why promise chains flatten automatically. You do not get a promise of a promise in normal .then(...) usage.
If You Need To Pass More Than One Value
A .then(...) callback only passes one fulfillment value forward, but that value can be an object or array.
If you need multiple related values later in the chain, package them intentionally instead of relying on outer mutable variables.
A Common Mistake: Calling Instead Of Wrapping
People often write:
That is wrong because console.log("value") runs immediately, and its return value is passed to .then(...) instead of a callback function.
Correct forms are:
or, if you only need the same function reference:
The same rule applies when you want to pass an extra value into the next handler. Wrap it in a function and return what the next step should receive.
Passing A Custom Value To The Next Step
Suppose the first async operation returns data you do not want to forward directly. Return the transformed value you actually want the next handler to receive.
If you want both the original user and a derived value later, return both in one object.
Error Flow Works The Same Way
If a handler throws, the chain becomes rejected and control moves to the nearest rejection handler.
Understanding this is important because success values are passed by return, while errors are passed by throw or by returning a rejected promise.
The Async/Await Equivalent
If promise chaining feels noisy, async and await express the same flow more directly:
This does not change the underlying rule. The next step still gets whatever value you produce from the previous one. await just makes the control flow easier to read.
Common Pitfalls
- Forgetting to
returna value from a.then(...)callback and accidentally passingundefinedforward. - Calling a function immediately instead of passing a callback function into
.then(...). - Using outer mutable variables when returning an object or array would be clearer.
- Returning a promise but also nesting another
.then(...)unnecessarily. - Mixing rejection handling between the second argument of
.then(...)and.catch(...)in a confusing way.
Summary
- The next
.then(...)receives whatever the previous handler returns. - Return a plain value to pass a value forward.
- Return a promise to make the chain wait for another async result.
- If you need multiple values later, return an object or array.
- If you forget to return, the next step receives
undefined.

