JavaScript Error nameProperty

JavaScript Error(错误) 对象JavaScript Error Object


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 nameDescriptionExample
EvalErrorError generated by the eval() function.Note:Newer versions of JavaScript useSyntaxErrorto replace EvalError. 
RangeErrorValue out of rangeTry it yourself
ReferenceErrorIllegal referenceTry it yourself
SyntaxErrorSyntax errorTry it yourself
TypeErrorType errorTry it yourself
URIErrorError generated by the encodeURI() functionTry 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 »

JavaScript Error(错误) 对象JavaScript Error Object

Other extensions