Skip to content
Related Articles

Related Articles

Improve Article

JavaScript | Error.prototype.toString() Method

  • Last Updated : 16 Apr, 2020
Geek Week

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

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!




My Personal Notes arrow_drop_up
Recommended Articles
Page :