Search This Blog

Tuesday, 2 August 2016

How to display the primitive value of a number in javascript?

Html page:

<button onclick="myFunction()">Try it</button>
<p id="P4"></p>

Javascript page:

<script>
    function myFunction() {
        var num = 15;
        var n = num.valueOf()
        document.getElementById("demo").innerHTML = n;
    }
</script>

Output:

15

No comments:

Post a Comment