9

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

throw new Error('Something went wrong');

/* vs */

throw Error('Something went wrong');
Offpics
  • 273
  • 3
  • 8

1 Answers1

11

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
  • 356,069
  • 52
  • 309
  • 320