The Number() can be used to convert JavaScript variables to numbers.

<!DOCTYPE html>
<html>
<body>

<p>The global JavaScript function Number() converts variables to numbers:</p>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = 
    Number(true) + "<br>" +
    Number(false) + "<br>" +
    Number(new Date()) + "<br>" +
    Number("  20") + "<br>" +
    Number("20  ") + "<br>" +
    Number("20 3");    
</script>

</body>
</html>

OUTPUT :


The global JavaScript function Number() converts variables to numbers:


  • Krishna Arora

    nice post