JavaScript Number NEGATIVE_INFINITY 属性
JavaScript Number NEGATIVE_INFINITY 是一个静态数据属性,表示负无穷大值。 JavaScript 中的负无穷值与全局"Infinity"属性的负值相同。
如果您尝试使用 x.NEGATIVE_INFINITY 访问它(其中"x"是一个变量),它将返回 undefined。
以下是有关 NEGATIVE_INFINITY 属性的一些要点 -
- 如果负无穷乘以 NaN,结果将为 NaN。
- 当负无穷乘以正无穷时,结果始终为负无穷。
- 如果负无穷乘以自身,结果始终为正无穷。
- 负无穷除以正无穷或除以自身都将返回 NaN。
- 当负无穷除以负数(负无穷本身除外)时始终返回正无穷大。
- 如果将其除以正无穷大以外的正数,则始终返回负无穷大。
语法
以下是 JavaScript 数字 NEGATIVE_INFINITY 属性的语法 -
Number.NEGATIVE_INFINITY
参数
- 不接受任何参数。
返回值
此属性没有返回值。
示例 1
以下程序演示了 JavaScript 数字 NEGATIVE_INFINITY 属性的用法。对于 Number.NEGATIVE_INFINITY,它将返回 '-Infinity'。
<html>
<head>
<title>JavaScript Number NEGATIVE_INFINITY Property</title>
</head>
<body>
<script>
document.write("Negative infinity = ", Number.NEGATIVE_INFINITY);
</script>
</body>
</html>
输出
上述程序将负无穷大返回为"-infinity"。
Negative infinity = -Infinity
示例 2
如果您尝试使用任何变量访问此属性,则会返回 undefined。
以下是 JavaScript 数字 NEGATIVE_INFINITY 属性的另一个示例。在这里,我们尝试使用 x.NEGATIVE_INFINITY 来查找负无穷大,其中"x"是一个值为 2 的变量。
<html>
<head>
<title>JavaScript Number NEGATIVE_INFINITY Property</title>
</head>
<body>
<script>
let x = 2;
document.write("x = ", x);
document.write("<br>Negative infinity = ", x.NEGATIVE_INFINITY);
</script>
</body>
</html>
输出
这将为 x.NEGATIVE_INFINITY 返回"undefined"。
x = 2 Negative infinity = undefined
示例 3
如果将 Number.NEGATIVE_INFINITY 属性乘以零,结果将为 NaN(非数字)。
<html>
<head>
<title>JavaScript Number NEGATIVE_INFINITY Property</title>
</head>
<body>
<script>
document.write("Result of 'Number.NEGATIVE_INFINITY * 0' = ", Number.NEGATIVE_INFINITY * 0);
</script>
</body>
</html>
输出
上述程序在输出中返回"NaN" -
Result of 'Number.NEGATIVE_INFINITY * 0' = NaN
示例 4
在此示例中,我们使用 Number.NEGATIVE_INFINITY 属性来检查一个数字是否等于负无穷大。如果是,则返回一个语句;否则,返回该数字本身。
<html>
<head>
<title>JavaScript Number NEGATIVE_INFINITY Property</title>
</head>
<body>
<script>
function check(num){
if(num == Number.NEGATIVE_INFINITY){
return "Number is equal to Negative infinity...!";
}
else{
return num;
}
}
//调用函数
document.write("Result of check(-Number.MAX_VALUE) is: ", check(-Number.MAX_VALUE));
document.write("<br>Result of check(-Number.MAX_VALUE * 2) is: ", check(-Number.MAX_VALUE*2));
</script>
</body>
</html>
输出
上述程序根据满足的条件返回输出 -
Result of check(-Number.MAX_VALUE) is: -1.7976931348623157e+308 Result of check(-Number.MAX_VALUE * 2) is: Number is equal to Negative infinity...!

