Number.POSITIVE_INFINITY

Number.POSITIVE_INFINITY 静态数据属性表示正 Infinity 值。

¥The Number.POSITIVE_INFINITY static data property represents the positive Infinity value.

Try it

¥Value

与全局 Infinity 属性的值相同。

¥The same as the value of the global Infinity property.

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

描述

¥Description

Number.POSITIVE_INFINITY 值的行为与数学无穷大略有不同:

¥The Number.POSITIVE_INFINITY value behaves slightly differently than mathematical infinity:

  • 任何正值(包括 POSITIVE_INFINITY)乘以 POSITIVE_INFINITY 就是 POSITIVE_INFINITY
  • 任何负值(包括 NEGATIVE_INFINITY)乘以 POSITIVE_INFINITY 就是 NEGATIVE_INFINITY
  • 任何正数除以 POSITIVE_INFINITY 就是 正零(如 IEEE 754 中所定义)。
  • 任何负数除以 POSITIVE_INFINITY 就是 负零(如 IEEE 754.1 中所定义)。
  • 零乘以 POSITIVE_INFINITY 等于 NaN
  • NaN 乘以 POSITIVE_INFINITYNaN
  • POSITIVE_INFINITY 除以 NEGATIVE_INFINITY 之外的任意负值,得到 NEGATIVE_INFINITY
  • POSITIVE_INFINITY 除以除 POSITIVE_INFINITY 之外的任意正值,得到 POSITIVE_INFINITY
  • POSITIVE_INFINITY 除以 NEGATIVE_INFINITYPOSITIVE_INFINITY,得到 NaN
  • Number.POSITIVE_INFINITY > x 对于除 POSITIVE_INFINITY 之外的任何数字 x 均成立。

你可以使用 Number.POSITIVE_INFINITY 属性来指示错误条件,如果成功则返回有限的数字。但请注意,在这种情况下,NaN 更合适。

¥You might use the Number.POSITIVE_INFINITY property to indicate an error condition that returns a finite number in case of success. Note, however, that NaN would be more appropriate in such a case.

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

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

示例

¥Examples

使用 POSITIVE_INFINITY

¥Using POSITIVE_INFINITY

在以下示例中,为变量 bigNumber 分配了一个大于最大值的值。当执行 if 语句时,bigNumber 的值为 Infinity,因此在继续之前将 bigNumber 设置为更易于管理的值。

¥In the following example, the variable bigNumber is assigned a value that is larger than the maximum value. When the if statement executes, bigNumber has the value Infinity, so bigNumber is set to a more manageable value before continuing.

js
let bigNumber = Number.MAX_VALUE * 2;

if (bigNumber === Number.POSITIVE_INFINITY) {
  bigNumber = returnFinite();
}

规范

Specification
ECMAScript Language Specification
# sec-number.positive_infinity

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看