Description
The Number() function is used to convert the object's argument to a number that represents the object's value.
This function has the form:
Number(object)
Parameter | Description |
---|---|
object | (optional) A JavaScript object. If no argument is provided, the function returns 0 |
Examples
The following example shows the basic use of this method.
<script>
var n1 = new Date();
var n2 = new String("123.45");
var n3 = new Boolean(true);
document.write(Number(n1));
document.write("<br />");
document.write(Number(n2));
document.write("<br />");
document.write(Number(n3));
</script>
This produces the following result:
Browser Support
Firefox | IE | Chrome | Opera | Safari |
---|---|---|---|---|