概述
Number.NEGATIVE_INFINITY 属性表示负无穷大。
不用创建一个 Number 实例,使用 Number.NEGATIVE_INFINITY 来访问该静态属性。
Number.NEGATIVE_INFINITY 属性的属性特性: |
|
|---|---|
| writable | false |
| enumerable | false |
| configurable | false |
描述
Number.NEGATIVE_INFINITY 的值和全局对象的 Infinity 属性的负值相同。
该值的行为同数学上的无穷大(infinity)有一点儿不同:
- 任何正值,包括
POSITIVE_INFINITY,乘以NEGATIVE_INFINITY为NEGATIVE_INFINITY。 - 任何负值,包括
NEGATIVE_INFINITY,乘以NEGATIVE_INFINITY为POSITIVE_INFINITY。 - 0 乘以
NEGATIVE_INFINITY为NaN. - NaN 乘以
NEGATIVE_INFINITY为NaN. NEGATIVE_INFINITY除以任何负值(除了NEGATIVE_INFINITY)为POSITIVE_INFINITY。NEGATIVE_INFINITY除以任何正值(除了POSITIVE_INFINITY)为NEGATIVE_INFINITY。NEGATIVE_INFINITY除以NEGATIVE_INFINITY或POSITIVE_INFINITY是NaN。- 任何数除以
NEGATIVE_INFINITY为 0。
为了成功返回一个有限值,你可能会使用 Number.NEGATIVE_INFINITY 属性来判断是否显示一个条件错误 。然而 isFinite 方法更适合这种情况。
示例
下例中,赋值给变量 smallNumber 一个明显小于 JavaScript 中的最小值的值。当 if 语句执行时,smallNumber 值为 "-Infinity",因此在继续执行代码前,smallNumber 被设为一个更容易管理的值。
var smallNumber = (-Number.MAX_VALUE) * 2
if (smallNumber == Number.NEGATIVE_INFINITY) {
smallNumber = returnFinite();
}
规范
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 1st Edition. Implemented in JavaScript 1.1 | Standard | Initial definition. |
| ECMAScript 5.1 (ECMA-262) Number.NEGATIVE_INFINITY |
Standard | |
| ECMAScript 2015 (6th Edition, ECMA-262) Number.NEGATIVE_INFINITY |
Standard |
浏览器规范
We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains.
Find out how you can help!
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |