JavaScript Error name property
Definition and Usage
The name property is used to set or return the name of the error.
The name property can return the following 6 different values.
| Error name | Description | Example |
|---|---|---|
| EvalError | Error generated by the eval() function. Note: The newer version of JavaScript uses SyntaxError to replace EvalError. | |
| RangeError | A value is out of the specified range | Try it |
| ReferenceError | Illegal reference | Try it |
| SyntaxError | Syntax errors | Try it |
| TypeError | Type error | Try it |
| URIError | Error generated by the encodeURI() function | Try it |
Tip: We can also refer to message the property to output more details about the error.
Syntax
errorObj.name
Parameter Description:
- none.
Return Value
Returns a string representing the name of the error.
Browser support
| property | |||||
|---|---|---|---|---|---|
| name | Yes | Yes | Yes | Yes | Yes |
Example
Example
Return an error name ("adddlert" function is not defined):
try
{
adddlert
(
"
Welcome guest!
"
)
;
}
catch
(
err
)
{
document
.
getElementById
(
"
demo
"
)
.
innerHTML
=
err
.
name
;
}
Try it »
JavaScript Error Object