Number.MAX_VALUE
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.MAX_VALUE
静态数据属性表示在 JavaScript 中可表示的最大数值。
尝试一下
function multiply(x, y) {
if (x * y > Number.MAX_VALUE) {
return "Process as Infinity";
}
return x * y;
}
console.log(multiply(1.7976931348623157e308, 1));
// Expected output: 1.7976931348623157e+308
console.log(multiply(1.7976931348623157e308, 2));
// Expected output: "Process as Infinity"
值
21024 - 1,或大约 1.7976931348623157E+308
。
Number.MAX_VALUE 的属性特性 | |
---|---|
可写 | 否 |
可枚举 | 否 |
可配置 | 否 |
描述
大于 MAX_VALUE
的值表示为 Infinity
并将丢失其实际值。
由于 MAX_VALUE
是 Number
对象的静态属性,你应该始终将其用作 Number.MAX_VALUE
,而不是作为一个数字值的属性。
示例
使用 MAX_VALUE
下面的代码对两个数值进行乘法运算。如果结果小于或等于 MAX_VALUE
,则调用函数 func1
;否则,调用函数 func2
。
js
if (num1 * num2 <= Number.MAX_VALUE) {
func1();
} else {
func2();
}
规范
Specification |
---|
ECMAScript® 2025 Language Specification # sec-number.max_value |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
MAX_VALUE |
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.