Skip to content
Related Articles

Related Articles

Improve Article

JavaScript | Error.prototype.toString() Method

  • Last Updated : 16 Apr, 2020

The Error.prototype.toString() method is an inbuilt method in JavaScript which is used to returns 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.

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



Example 1:




var geeks1 = new Error();
document.writeln(geeks1.toString()); 
document.writeln("<br>");
   
geeks1.name = undefined;
document.writeln(geeks1.toString()); 
document.writeln("<br>");
  
geeks1.name = 'GeeksForGeeks';
document.writeln(geeks1.toString());

Output:

Error
Error
GeeksForGeeks

Example 2:




var geeks = new Error('Error.prototype.toString()');
document.writeln(geeks.toString()); 
document.writeln("<br>");
   
geeks.name = undefined;
document.writeln(geeks.toString()); 
document.writeln("<br>");
   
geeks.name = '';
document.writeln(geeks.toString()); 
document.writeln("<br>");
   
geeks.message = "Error Type";
document.writeln(geeks.toString());
document.writeln("<br>");
   
geeks.message = undefined;
document.writeln(geeks.toString());
document.writeln("<br>");
   
geeks.name = 'GeeksForGeeks';
document.writeln(geeks.toString());

Output:

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

GeeksForGeeks

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

  • Google Chrome
  • Firefox
  • Edge



My Personal Notes arrow_drop_up
Recommended Articles
Page :