JavaScript string.toString() Method
The string.toString() is an inbuilt method in JavaScript that 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 representing the given string object.
Below is an example of the string.toString() Method.
Example: This example shows the basic use of the string.toString() Method in Javascript.
javascript
<script> // Taking a string as input and printing it // with the help of string.toString() function var a = new String( "GfG" ); console.log(a.toString()); </script> |
Output:
GfG
JavaScript codes to show the working of string.toString() method:
Example 1: Taking a string as input and printing it with the help of string.toString() function
javascript
<script> // Taking a string as input and printing it // with the help of string.toString() function var a = new String( "GeeksforGeeks" ); console.log(a.toString()); </script> |
Output:
GeeksforGeeks
Example 2: Taking a string as input and printing it with the help of string.toString() function.
javascript
<script> // Taking a string as input and printing it // with the help of string.toString() function var a = new String( "GFGGFG" ); console.log(a.toString()); </script> |
Output:
GfGGfG
We have a complete list of Javascript string methods, to check those please go through this Javascript String Complete reference article.
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
Please Login to comment...