What is the output of the following code? const p = Promise.reject(new Error(‘fail’)); setTimeout(() => p.catch(e => console.log(e.message)), 0);

JavaScript Professional Hard

JavaScript Professional — Hard

What is the output of the following code? const p = Promise.reject(new Error(‘fail’)); setTimeout(() => p.catch(e => console.log(e.message)), 0);

Key points

  • Asynchronous catch handlers prevent unhandled rejections
  • setTimeout delays the catch execution but does not affect handling
  • The error message is accessed through 'e.message' in the catch block

Ready to go further?

Related questions