Error.prototype.name
The name property represents a name for the type of error. The initial value is "Error".
Description
By default, Error instances are given the name "Error". The name property, in addition to the message property, is used by the Error.prototype.toString() method to create a string representation of the error.Examples
Throwing a custom error
const e = new Error('Malformed input'); // e.name is 'Error'

e.name = 'ParseError';
throw e;
// e.toString() would return 'ParseError: Malformed input'
Specifications

Specification
ECMAScript Language Specification # sec-error.prototype.name

Browser compatibility




Desktop
Mobile
Server



Chrome
Edge
Firefox
Internet Explorer
Opera
Safari
WebView Android
Chrome Android
Firefox for Android
Opera Android
Safari on IOS
Samsung Internet
Deno
Node.js



name
1
12
1
6
4
1
4.4
18
4
10.1
1
1.0
1.0
0.10.0


See also
 Error.prototype.message Error.prototype.toString() 

Found a problem with this page?

Edit on GitHub
Source on GitHub
Report a problem with this content on GitHub
Want to fix the problem yourself? See our Contribution guide.


Last modified: May 22, 2022, by MDN contributors


    
{'path': 'public/docs/javascript/global_objects/error/name.html', 'source': 'DevDocs.IO'}