1 Example(s) of JavaScript valueOf function


Description :

JavaScript valueOf function will return the primitive value of a string. See the code snippet:



JavaScript valueOf function Example - 1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<button onclick="convertToPrimitiveValue()">Display the value</button>
<p id="sample"></p>
<script>
function convertToPrimitiveValue() {
    var str = "I love learnKode";
    var result = str.valueOf();
    document.getElementById("sample").innerHTML = result;
}
</script>


</body>
</html>

Output