This solution is generated by ChatGPT, correctness is not guaranteed.

AI solution for JavaScript Quiz on BFE.dev
4. Promise then callbacks II

The code outputs:

1 2 undefined 3 4 undefined 10

Explanation:

  • Promise.resolve(1) creates a resolved promise with value 1.
  • The first then callback logs 1 and returns 2.
  • The second then callback logs 2.
  • The third then callback logs undefined (because it doesn't have a return value).
  • The fourth then callback returns a promise, which resolves to 3 and logs 3.
  • The fifth then callback returns a rejected promise with value 4.
  • The catch method catches the rejection and logs 4.
  • The finally method logs undefined and returns 10.
  • The last then callback logs 10.