JavaScript string.toString() Method
Below is the example of the string.toString() Method.
- Example:
<script>// Taking a string as input and printing it// with the help of string.toString() functionvara =newString("GfG");document.write(a.toString());</script>chevron_rightfilter_none - 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:
<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> |
chevron_right
filter_none
Output:
GeeksforGeeks
Code #2:
|
|
chevron_right
filter_none
Output:
GfGGfG
Supported Browsers:
- Google Chrome
- Internet Explorer
- Firefox
- Apple Safari
- Opera


