Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript Error name property

JavaScript Error name property

JavaScript Error Object JavaScript Error Object


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:

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 JavaScript Error Object