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

JavascriptFront End TechnologyObject Oriented Programming

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.

raja
Published on 02-Dec-2019 05:33:49
Advertisements