Skip to content
Related Articles

Related Articles

JavaScript string.toString() Method

View Discussion
Improve Article
Save Article
  • Last Updated : 07 Oct, 2021
View Discussion
Improve Article
Save Article

Below is the example of the string.toString() Method. 
 

  • Example: 
     

javascript




<script>
    // Taking a string as input and printing it
    // with the help of string.toString() function
    var a = new String("GfG");
    document.write(a.toString());
</script>


  • Output: 
     
GfG

The string.toString() is an inbuilt method in JavaScript which is used to return the given string itself.
Syntax: 
 

string.toString()

Parameters: It does not accept any parameter.
Return Values: It returns a new string represent the given string object.
JavaScript code to show the working of string.toString() method: 
Code #1: 
 

javascript




<script>
 
    // Taking a string as input and printing it
    // with the help of string.toString() function
    var a = new String("GeeksforGeeks");
    document.write(a.toString());
 
</script>


Output: 
 

GeeksforGeeks

Code #2: 
 

javascript




 


Output: 
 

GfGGfG

Supported Browsers: 
 

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 3 and above
  • Opera 3 and above
  • Safari 1 and above

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!