3

Are there any drawbacks of throwing Errors without the new keyword?

throw new Error('Something went wrong');

/* vs */

throw Error('Something went wrong');
Offpics
  • 113
  • 1
  • 7

1 Answers1

7

They are exactly the same, as guaranteed by the specification:

19.5.1 The Error Constructor

The Error constructor:

...

creates and initializes a new Error object when called as a function rather than as a constructor. Thus the function call Error(…) is equivalent to the object creation expression new Error(…) with the same arguments.

Community
  • 1
  • 1
CertainPerformance
  • 313,535
  • 40
  • 245
  • 254