JavaScript String valueOf() Method
The JavaScript String valueOf() Method is an inbuilt method in JavaScript that is used to return the value of the given string.
Syntax:
string.valueOf()
Parameters: It does not accept any parameter.
Return Values: It returns a string that represents the value of the given string object.
Below is an example of the string.valueOf() Method.
Example 1:
javascript
<script> var a = new String( "GeeksforGeeks" ); console.log(a.valueOf()); </script> |
Output:
GeeksforGeeks
Example 2:
javascript
<script> // Taking a string as input and printing it // with the help of string.valueOf() function var a = new String( "GeeksforGeeks" ); console.log(a.valueOf()); </script> |
Output:
GeeksforGeeks
Example 2:
javascript
<script> // Taking a string as input and printing it // with the help of string.valueOf() function var a = new String( "Geeks" ); var b = new String( "for" ); var c = new String( "Geeks" ); console.log(a.valueOf(),b.valueOf(),c.valueOf()); </script> |
Output:
GeeksforGeeks
We have a complete list of Javascript string methods, to check those please go through this Javascript String Complete reference article.
Supported Browser:
- Chrome 1 and above
- Edge 12 and above
- Firefox 1 and above
- Internet Explorer 4 and above
- Opera 3 and above
- Safari 1 and above
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.
Please Login to comment...