JavaScript Error.prototype.name Property
The name property of an Error gives its type, such as Error, TypeError or a custom name.
Description
The name property identifies the type of error. Built-in errors have names such as "TypeError" and "RangeError". When creating a custom error class, set this.name so the type appears in logs. To check types, instanceof is more reliable than comparing names.
Custom error classes can set name as a class field, as shown above, or in the constructor after calling super(). Converting an error to a string, as when logging it, gives "name: message", so a meaningful name makes logs easier to scan.
Some web APIs throw DOMException objects, whose name identifies the problem, such as "AbortError" for aborted requests or "NotAllowedError" for blocked permissions; checking err.name is the standard way to handle those.
Syntax
error.nameValue
A string: the type of error, such as "TypeError".
Example
Browser Support
The following information will show you the current browser support for the Error.prototype.name property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





