Number.POSITIVE_INFINITY 特性表示正无穷大值。

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

特性属性在 Number.POSITIVE_INFINITY
可写 no
可枚举 no
可配置 no

描述

Number.POSITIVE_INFINITY 是相同值的全局对象 Infinity 特性。

This value behaves slightly differently than mathematical infinity:

  • Any positive value, including POSITIVE_INFINITY , multiplied by POSITIVE_INFINITY is POSITIVE_INFINITY .
  • Any negative value, including NEGATIVE_INFINITY , multiplied by POSITIVE_INFINITY is NEGATIVE_INFINITY .
  • Any positive number divided by POSITIVE_INFINITY is positive Zero.
  • Any negative number divided by POSITIVE_INFINITY is negative Zero.
  • Zero multiplied by POSITIVE_INFINITY is NaN .
  • NaN multiplied by POSITIVE_INFINITY is NaN .
  • POSITIVE_INFINITY , divided by any negative value except NEGATIVE_INFINITY , is NEGATIVE_INFINITY .
  • POSITIVE_INFINITY , divided by any positive value except POSITIVE_INFINITY , is POSITIVE_INFINITY .
  • POSITIVE_INFINITY , divided by either NEGATIVE_INFINITY or POSITIVE_INFINITY , is 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 isFinite would be more appropriate in such a case.

因为 POSITIVE_INFINITY is a static property of Number , you always use it as Number.POSITIVE_INFINITY , rather than as a property of a Number object you created.

范例

使用 POSITIVE_INFINITY

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.

var bigNumber = Number.MAX_VALUE * 2;
if (bigNumber == Number.POSITIVE_INFINITY) {
  bigNumber = returnFinite();
}
					

规范

规范
ECMAScript (ECMA-262)
在该规范中的 Number.POSITIVE_INFINITY 定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
POSITIVE_INFINITY Chrome 1 Edge 12 Firefox 1 IE 4 Opera 3 Safari 1 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0 nodejs 0.1.100

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: