Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

Why does a .then() without return pass undefined?

Do you know what will be the output of this code?

JavaScript
Promise.resolve(1)
  .then((x) => x + 1)
  .then((x) => {
    x * 2;
  })
  .then((x) => console.log(x));
Show answer and explanation

The answer is undefined.

The second callback uses braces, so it needs an explicit return. Without one it returns undefined, and that’s what the next .then receives.

Take the full quiz Next question →

More Promises & Async questions

  1. Why does an arrow function in setTimeout keep this?
  2. Why does a Promise run before setTimeout 0?
  3. What does an async function return in JavaScript?
  4. What runs first after await in JavaScript?
  5. Is the Promise constructor callback synchronous?

Related topics