JavaScript String valueOf() method : The valueOf() method is used to cast the string object to the primitive value. It doesn't change the original string.
Syntax of the valueOf() method :
string.valueOf()
Example of valueOf() method : Here I will show you how to use valueOf() method in JavaScript.
<!DOCTYPE html>
<html>
<body>
<p>To return the primitive value of the string object, click the button.</p>
<button onclick="castToPrimitive()">convert</button>
<p id="container"></p>
<script>
function castToPrimitive() {
var msg = "Hey! how are you ?";
var result = msg.valueOf();
document.getElementById("container").innerHTML = result;
}
</script>
</body>
</html>
Output : Hey! how are you ?
0 Comment(s)