What is the output of the following? “`js async function foo() { try { await Promise.reject(new Error(‘oops’)); } catch(e) { console.log(e.message); } } foo(); “`

JavaScript Professional Medium

JavaScript Professional — Medium

What is the output of the following? “`js async function foo() { try { await Promise.reject(new Error(‘oops’)); } catch(e) { console.log(e.message); } } foo(); “`

Key points

  • The await keyword is used to handle asynchronous operations in JavaScript.
  • The Promise.reject() method creates a rejected Promise with a specified reason.
  • The catch block is used to handle any errors that occur during the Promise execution.

Ready to go further?

Related questions