Wednesday, January 21, 2026
HomeLanguagesJavascriptJavaScript Error.prototype.toString() Method

JavaScript Error.prototype.toString() Method

The Error.prototype.toString() method is an inbuilt method in JavaScript that is used to return a string representing the specified Error object. 

Syntax:

e.toString()

Parameters: This method does not accept any parameters. 

Return value: This method returns a string representing the specified Error object. 

The below examples illustrate the Error.prototype.toString() Method in JavaScript: 

Example 1: In this example, we will try to return a string using the Error.prototype.toString() Method in JavaScript.

javascript




let neveropen1 = new Error();
console.log(neveropen1.toString());
 
neveropen1.name = undefined;
console.log(neveropen1.toString());
 
neveropen1.name = 'GeeksForGeeks';
console.log(neveropen1.toString());


Output:

Error
Error
GeeksForGeeks

Example 2: 

javascript




let neveropen = new Error('Error.prototype.toString()');
console.log(neveropen.toString());
 
neveropen.name = undefined;
console.log(neveropen.toString());
 
neveropen.name = '';
console.log(neveropen.toString());
 
neveropen.message = "Error Type";
console.log(neveropen.toString());
 
neveropen.message = undefined;
console.log(neveropen.toString());
 
neveropen.name = 'GeeksForGeeks';
console.log(neveropen.toString());


Output:

Error: Error.prototype.toString()
Error: Error.prototype.toString()
Error.prototype.toString()
Error Type

GeeksForGeeks

We have a complete list of Javascript Error Objects, to check those please go through the Javascript Error Object Complete Reference article

Supported Browsers: The browsers supported by Error.prototype.toString() Method are listed below:

  • Google Chrome
  • Firefox
  • Edge
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12064 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7220 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS