The Error
constructor creates an error object.
new Error([message[, fileName[, lineNumber]]])
message
Optional
fileName
Optional
fileName
property on the created Error
object. Defaults to the name of the file containing the code that called the Error()
constructor.lineNumber
Optional
lineNumber
property on the created Error
object. Defaults to the line number containing the Error()
constructor invocation.When Error
is used like a function -- without new
, it will return an Error
object. Therefore, a mere call to Error
will produce the same output that constructing an Error
object via the new
keyword would.
// this... const x = Error('I was created using a function call!') // ...has the same functionality as this. const y = new Error('I was constructed via the "new" keyword!')
Desktop | ||||||
---|---|---|---|---|---|---|
Error() constructor |
1 | 12 | 1 | 6 | 4 | 1 |
Mobile | ||||||
---|---|---|---|---|---|---|
Error() constructor |
1 | 18 | 4 | 10.1 | 1 | 1.0 |
Server | |
---|---|
Error() constructor |
0.1.100 |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error