Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ Number.isNaN(value)

## Description

Due to both equality operators, {{jsxref("Operators", "==",
"#Equality")}} and {{jsxref("Operators", "===", "#Identity")}},
Due to both equality operators, [`==`](/en-US/docs/Web/JavaScript/Reference/Operators/Equality) and [`===`](/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality),
evaluating to `false` when checking if {{jsxref("NaN")}} _is_
{{jsxref("NaN")}}, the function `Number.isNaN()` has become necessary. This
situation is unlike all other possible value comparisons in JavaScript.

Since `x !== x` is only true for `NaN` among all possible JavaScript values, `Number.isNaN(x)` can also be replaced with a test for `x !== x`, despite the latter being less readable.

In comparison to the global {{jsxref("isNaN", "isNaN()")}} function,
`Number.isNaN()` doesn't suffer the problem of forcefully converting the
parameter to a number. This means it is now safe to pass values that would normally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ provided value is a number that is a _safe integer_.

{{EmbedInteractiveExample("pages/js/number-issafeinteger.html")}}

## Syntax

```js
Number.isSafeInteger(testValue)
```

### Parameters

- `testValue`
- : The value to be tested for being a safe integer.

### Return value

The boolean value `true` if the given value is a number that is a
safe integer. Otherwise `false`.

## Description

A safe integer is an integer that

- can be exactly represented as an IEEE-754 double precision number, and
Expand All @@ -29,7 +47,7 @@ represented in IEEE-754, but the integer `2^53 + 1` can't be
directly represented in IEEE-754 but instead rounds to `2^53` under
round-to-nearest and round-to-zero rounding. The safe integers consist of all integers
from `-(2^53 - 1)` inclusive to `2^53 - 1`
inclusive (± `9007199254740991` or ± 9,007,199,254,740,991).
inclusive (± `9_007_199_254_740_991`).

Handling values larger or smaller than \~9 quadrillion with full precision requires
using an [arbitrary precision arithmetic library](https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic).
Expand All @@ -38,22 +56,6 @@ information on floating point representations of numbers.

For larger integers, consider using the {{jsxref("BigInt")}} type.

## Syntax

```js
Number.isSafeInteger(testValue)
```

### Parameters

- `testValue`
- : The value to be tested for being a safe integer.

### Return value

The boolean value `true` if the given value is a number that is a
safe integer. Otherwise `false`.

## Examples

### Using isSafeInteger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ The **`Number.MIN_VALUE`** property represents the smallest positive numeric val

## Description

`Number.MIN_VALUE` is the smallest positive number (not the most negative number) that can be represented within float precision — in other words, the number closest to 0. That's approximately `5E-324`. The ECMAScript spec doesn't define a precise value that implementations are required to support — instead the spec says, _"must be the smallest non-zero positive value that can actually be represented by the implementation"_. But in practice, its precise value in browsers and in Node.js is `2^-1074`.
`Number.MIN_VALUE` is the smallest positive number (not the most negative number) that can be represented within float precision — in other words, the number closest to 0. The ECMAScript spec doesn't define a precise value that implementations are required to support — instead the spec says, _"must be the smallest non-zero positive value that can actually be represented by the implementation"_. This is because small IEEE-754 floating point numbers are [denormalized](https://en.wikipedia.org/wiki/Subnormal_number), but implementations are not required to support this representation, in which case `Number.MIN_VALUE` may be larger.

In practice, its precise value in mainstream engines like V8 (used by Chrome, Edge, Node.js), SpiderMonkey (used by Firefox), and JavaScriptCore (used by Safari) is `2^-1074`, or `5E-324`.

Because `MIN_VALUE` is a static property of {{jsxref("Number")}}, you always use it as `Number.MIN_VALUE`, rather than as a property of a {{jsxref("Number")}} object you created.

Expand Down