The ES5 language spec clearly states that Error(foo)
does the same thing as new Error(foo)
.
But I notice that in the wild, the longer new
Is there some reason for this?
It's simply the habit of always calling constructors with new
. Consistency rules!
It's a good practice to do even when they work without new
, and recommended by several style guides and related tooling. Btw, since ES6 Error is subclassible, and its subclasses will require new
.