Number.NEGATIVE_INFINITY property represents the negative Infinity value.

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.NEGATIVE_INFINITY
可写 no
可枚举 no
可配置 no

描述

Number.NEGATIVE_INFINITY is the same as the negative value of the global object's Infinity 特性。

This value behaves slightly differently than mathematical infinity:

  • Any positive value, including POSITIVE_INFINITY , multiplied by NEGATIVE_INFINITY is NEGATIVE_INFINITY .
  • Any negative value, including NEGATIVE_INFINITY , multiplied by NEGATIVE_INFINITY is POSITIVE_INFINITY .
  • Any positive value divided by NEGATIVE_INFINITY is negative zero.
  • Any negative value divided by NEGATIVE_INFINITY is positive zero.
  • Zero multiplied by NEGATIVE_INFINITY is NaN .
  • NaN multiplied by NEGATIVE_INFINITY is NaN .
  • NEGATIVE_INFINITY , divided by any negative value except NEGATIVE_INFINITY , is POSITIVE_INFINITY .
  • NEGATIVE_INFINITY , divided by any positive value except POSITIVE_INFINITY , is NEGATIVE_INFINITY .
  • NEGATIVE_INFINITY , divided by either NEGATIVE_INFINITY or POSITIVE_INFINITY , is NaN .

You might use the Number.NEGATIVE_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.

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

范例

使用 NEGATIVE_INFINITY

In the following example, the variable smallNumber is assigned a value that is smaller than the minimum value. When the if statement executes, smallNumber has the value -Infinity , so smallNumber is set to a more manageable value before continuing.

var smallNumber = (-Number.MAX_VALUE) * 2;
if (smallNumber === Number.NEGATIVE_INFINITY) {
  smallNumber = returnFinite();
}
					

规范

规范
ECMAScript (ECMA-262)
The definition of 'Number.NEGATIVE_INFINITY' in that specification.

浏览器兼容性

更新 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
NEGATIVE_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

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: