What is the output of the following code? “`js const p = new Promise((resolve) => resolve(42)); p.then(v => v * 2) .then(v => console.log(v)); “`

JavaScript Associate Medium

JavaScript Associate — Medium

What is the output of the following code? “`js const p = new Promise((resolve) => resolve(42)); p.then(v => v * 2) .then(v => console.log(v)); “`

Key points

  • The Promise resolves to 42
  • The value is multiplied by 2 in the first `then` block
  • The final result is 84
  • The `console.log` statement outputs the final value

Ready to go further?

Related questions