Visit Mozilla.org

Referencia de JavaScript 1.5:Funciones globales:Number

De MDC


Tabla de contenidos

[editar] Summary

Core Function

Converts the specified value to a number.

[editar] Syntax

Number(val)

[editar] Parameters

val 
A value.

[editar] Description

Number is a top-level function and is not associated with any object. It is also a constructor for Number objects.

When the value is a Date object, Number returns a number in milliseconds measured from 01 January, 1970 UTC (GMT), positive after this date, negative before.

If val is a string that does not contain a well-formed numeric literal, Number returns NaN.

[editar] Examples

[editar] Example: Using Number to convert a Date object

The following example converts the Date object to a numerical value:

var d = new Date("December 17, 1995 03:24:00");
alert(Number(d));

This displays a dialog box containing "819199440000".

[editar] See also

Number