Both are fine; this is explicitly stated in the specification: '... Thus the function call Error(…) is equivalent to the object creation expression new Error(…) with the same arguments.'
TIL Error('message')
and new Error('message')
are equivalent in JavaScript. I’ve always used new
.
Responses
See how to respond...
Respond via email
If you'd prefer to message me directly, send an email. If you'd also like your message to be visible on the site I can add it as a comment.
Reply via Email
Respond from another site
Responses are collected from posts on other sites. Have you posted somewhere that links to this page? If so, share the link!