Number.MAX_VALUE

Number.MAX_VALUE 静态数据属性表示 JavaScript 中可表示的最大数值。

¥The Number.MAX_VALUE static data property represents the maximum numeric value representable in JavaScript.

Try it

¥Value

21024 - 2971,或大约 1.7976931348623157E+308

¥21024 - 2971, or approximately 1.7976931348623157E+308.

Property attributes of Number.MAX_VALUE
Writable no
Enumerable no
Configurable no

描述

¥Description

大于 MAX_VALUE 的值将表示为 Infinity,并将丢失其实际值。

¥Values larger than MAX_VALUE are represented as Infinity and will lose their actual value.

由于 MAX_VALUENumber 的静态属性,因此你始终将其用作 Number.MAX_VALUE,而不是作为数字值的属性。

¥Because MAX_VALUE is a static property of Number, you always use it as Number.MAX_VALUE, rather than as a property of a number value.

示例

¥Examples

使用 MAX_VALUE

¥Using MAX_VALUE

以下代码将两个数值相乘。如果结果小于或等于 MAX_VALUE,则调用 func1 函数;否则,调用 func2 函数。

¥The following code multiplies two numeric values. If the result is less than or equal to MAX_VALUE, the func1 function is called; otherwise, the func2 function is called.

js
if (num1 * num2 <= Number.MAX_VALUE) {
  func1();
} else {
  func2();
}

规范

Specification
ECMAScript Language Specification
# sec-number.max_value

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看