JavaScript Error nameProperty
Definition and Usage
The name property is used to set or return the error name.
The name property can return the following 6 different values.
| Error name | Description | Example |
|---|---|---|
| EvalError | Error generated by the eval() function.Note:Newer versions of JavaScript useSyntaxErrorto replace EvalError. | |
| RangeError | Value out of range | Try it yourself |
| ReferenceError | Illegal reference | Try it yourself |
| SyntaxError | Syntax error | Try it yourself |
| TypeError | Type error | Try it yourself |
| URIError | Error generated by the encodeURI() function | Try it yourself |
Tip:We can also refer tomessagethe property to output more content of the error.
Syntax
errorObj.name
Parameter description:
- None.
Return value
Returns a string representing the error name.Browser Support
| Property | |||||
|---|---|---|---|---|---|
| name | Yes | Yes | Yes | Yes | Yes |
Example
Example
Returns an error name (the "adddlert" function is not defined):
try {
adddlert("Welcome guest!");
}
catch(err) {
document.getElementById("demo").innerHTML = err.name;
}
Try it yourself »
Other extensions
JavaScript Error Object