Number.MIN_SAFE_INTEGER
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Number.MIN_SAFE_INTEGER
静态数据属性代表在 JavaScript 中最小的安全整数(-253 – 1)。
要表示比这小的整数,请考虑使用 BigInt
。
尝试一下
const x = Number.MIN_SAFE_INTEGER - 1;
const y = Number.MIN_SAFE_INTEGER - 2;
console.log(Number.MIN_SAFE_INTEGER);
// Expected output: -9007199254740991
console.log(x);
// Expected output: -9007199254740992
console.log(x === y);
// Expected output: true
值
-9007199254740991
(-9,007,199,254,740,991,或大约 -9 千万亿)。
Number.MIN_SAFE_INTEGER 的属性特性 | |
---|---|
可写 | 否 |
可枚举 | 否 |
可配置 | 否 |
描述
双精度浮点格式只有 52 位用于表示尾数,因此它只能安全地表示介于 -(253 – 1) 和 253 – 1 之间的整数。本文中,“安全”指的是能够精确表示整数并正确比较它们。例如,Number.MIN_SAFE_INTEGER - 1 === Number.MIN_SAFE_INTEGER - 2
的结果将为真,这在数学上是不正确的。有关更多信息,请参阅 Number.isSafeInteger()
。
由于 MIN_SAFE_INTEGER
是 Number
的静态属性,你应该始终将其使用为 Number.MIN_SAFE_INTEGER
,而不是一个数字值的属性。
示例
使用 MIN_SAFE_INTEGER
js
Number.MIN_SAFE_INTEGER; // -9007199254740991
-(2 ** 53 - 1); // -9007199254740991
规范
Specification |
---|
ECMAScript® 2025 Language Specification # sec-number.min_safe_integer |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
MIN_SAFE_INTEGER |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.