We're looking for a person or people to help audit MDN to find places we could speed up. Is this you or someone you know? Check out the RFP: https://mzl.la/2IHcMiE

Tento překlad není kompletní. Prosím pomozte přeložit tento článek z angličtiny.

The Number JavaScript object is a wrapper object allowing you to work with numerical values. A Number object is created using the Number() constructor.


new Number(value);


The numeric value of the object being created.


The primary uses for the Number object are:

  • If the argument cannot be converted into a number, it returns NaN.
  • In a non-constructor context (i.e., without the new operator), Number can be used to perform a type conversion.


The smallest interval between two representable numbers.
The maximum safe integer in JavaScript (253 - 1).
The largest positive representable number.
The minimum safe integer in JavaScript (-(253 - 1)).
The smallest positive representable number - that is, the positive number closest to zero (without actually being zero).
Special "not a number" value.
Special value representing negative infinity; returned on overflow.
Special value representing infinity; returned on overflow.
Allows the addition of properties to a Number object.
Properties inherited from Function:


For methods available on Číslo (Number) instances, see Methods of Číslo (Number) instances.
Determine whether the passed value is NaN.
Determine whether the passed value is a finite number.
Determine whether the passed value is an integer.
Determine whether the passed value is a safe integer (number between -(253 - 1) and 253 - 1).
Used to evaluate the passed value and convert it to an integer (or Infinity), but has been removed.
The value is the same as parseFloat of the global object.
The value is the same as parseInt of the global object.
Methods inherited from Function:

Number instances

All Number instances inherit from Number.prototype. The prototype object of the Number constructor can be modified to affect all Number instances.


Returns a string representing the number in exponential notation.
Returns a string representing the number in fixed-point notation.
Returns a string with a language sensitive representation of this number. Overrides the Object.prototype.toLocaleString() method.
Returns a string representing the number to a specified precision in fixed-point or exponential notation.
Returns an object literal representing the specified Number object; you can use this value to create a new object. Overrides the Object.prototype.toSource() method.
Returns a string representing the specified object in the specified radix (base). Overrides the Object.prototype.toString() method.
Returns the primitive value of the specified object. Overrides the Object.prototype.valueOf() method.


Example: Using the Number object to assign values to numeric variables

The following example uses the Number object's properties to assign values to several numeric variables:

var biggestNum = Number.MAX_VALUE;
var smallestNum = Number.MIN_VALUE;
var infiniteNum = Number.POSITIVE_INFINITY;
var negInfiniteNum = Number.NEGATIVE_INFINITY;
var notANum = Number.NaN;

Example: Integer range for Number

The following example shows minimum and maximum integer values that can be represented as Number object (for details, refer to EcmaScript standard, chapter 8.5 The Number Type):

var biggestInt = 9007199254740992;
var smallestInt = -9007199254740992;

When parsing data that has been serialized to JSON, integer values falling out of this range can be expected to become corrupted when JSON parser coerces them to Number type. Using String instead is a possible workaround.

Example: Using Number to convert a Date object

The following example converts the Date object to a numerical value using Number as a function:

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

This displays "819199440000".

Example: Convert numeric strings to numbers

Number("123")     // 123
Number("")        // 0
Number("0x11")    // 17
Number("0b11")    // 3
Number("0o11")    // 9
Number("foo")     // NaN
Number("100a")    // NaN


Specification Status Comment
ECMAScript 1st Edition. Standard Initial definition. Implemented in JavaScript 1.1.
ECMAScript 5.1 (ECMA-262)
The definition of 'Number' in that specification.
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Number' in that specification.
Standard New methods and properties added: (EPSILON, isFinite, isInteger, isNaN, parseFloat, parseInt)

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See also

Štítky a přispěvatelé do dokumentace

 Přispěvatelé této stránky: fscholz, teoli, m93a
 Poslední aktualizace od: fscholz,