The valueOf()
method returns the primitive value from a String object.
String valueOf() |
Yes | Yes | Yes | Yes | Yes |
stringObject.valueOf();
None.
A string primitive value of a String Object.
<!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: