Home >>JavaScript String Methods >JavaScript String valueOf() Method
JavaScript valueOf() method is used to return the primitive value of a given input String object. It is usually called automatically by JavaScript and not explicitly in code.
Syntax:string.valueOf()
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
valueOf() | Yes | Yes | Yes | Yes | Yes |
<html> <body> <p>Click the button to see the Output.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var str = "PHPTPOINT"; var res = str.valueOf(); document.getElementById("demo").innerHTML = res; } </script> </body> </html>
Click the button to see the Output.
<html> <body> <p>Click the button to see the Output.</p> <button onclick="myFunction1()">Try it</button> <p id="demo1"></p> <script> function myFunction1() { var str = "Abhimanyu"; var res = str.valueOf(); document.getElementById("demo1").innerHTML = res; } </script> </body> </html>
Click the button to see the Output.