Latest web development tutorials

JavaScript Number () function

Function Reference Manual JavaScript Global Functions

Definition and Usage

() Function of the value of the object Number converted to digital.

If the value of an object can not be converted to digital, then the Number () function returns NaN.

grammar

Number(object)

参数 描述
object 可选。一个 JavaScript 对象。如果没有提供参数,则返回0。


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support Number () function


Tips and Notes

Note: If the parameter is a Date object, Number () returns the number of milliseconds since January 1, 1970 to the present.


Examples

Examples

The object is converted to different numbers:

<script>

var test1= new Boolean(true);
var test2= new Boolean(false);
var test3= new Date();
var test4= new String("999");
var test5= new String("999 888");

document.write(Number(test1)+ "<br>");
document.write(Number(test2)+ "<br>");
document.write(Number(test3)+ "<br>");
document.write(Number(test4)+ "<br>");
document.write(Number(test5)+ "<br>");

</script>

Examples of the above output:


try it"


Function Reference Manual JavaScript Global Functions