Javascript Reference - JavaScript String valueOf() Method








The valueOf() method returns the primitive value from a String object.

Browser Support

String valueOf() Yes Yes Yes Yes Yes

Syntax

stringObject.valueOf();

Parameters

None.

Return Value

A string primitive value of a String Object.





Example


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from  w  w w.  j av a 2  s. com-->
    var str = "Hello World!";
    var res = str.valueOf();
    document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>

The code above is rendered as follows: