What is the difference between 'throw new Error' and 'throw someObject' in javascript?


The difference between 'throw new Error' and 'throw someObject' in javascript is that throw new Error wraps the error passed to it in the following format −

{
   name: 'Error',
   message: 'Whatever you pass in the constructor'
}

The throw someObject will throw the object as is and will not allow any further code execution from the try block, ie same as throw new Error.

Updated on: 02-Dec-2019

433 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements