Computer >> Computer tutorials >  >> Programming >> Javascript

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.