Error.prototype.name
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Thename data property ofError.prototype is shared by allError instances. It represents the name for the type of error. ForError.prototype.name, the initial value is"Error". Subclasses likeTypeError andSyntaxError provide their ownname properties.
In this article
Value
A string. ForError.prototype.name, the initial value is"Error".
Property attributes ofError.prototype.name | |
|---|---|
| Writable | yes |
| Enumerable | no |
| Configurable | yes |
Description
By default,Error instances are given the name "Error". Thename property, in addition to themessage property, is used by theError.prototype.toString() method to create a string representation of the error.
Examples
>Throwing a custom error
js
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® 2026 Language Specification> # sec-error.prototype.name> |