Number.NEGATIVE_INFINITY คือค่าพิเศษแทนค่าที่น้อยกว่า Number.MIN_VALUE แสดงเป็น "-Infinity" พฤติกรรมคล้ายอนันต์ในคณิตศาสตร์
ตัวอย่าง
<html>
<head>
<script>
function showValue() {
var smallNumber = (-Number.MAX_VALUE) * 2;
if (smallNumber == Number.NEGATIVE_INFINITY) {
alert("Value of smallNumber: " + smallNumber); // -Infinity
}
}
</script>
</head>
<body>
<p>Click the following to see the result:</p>
<form>
<input type="button" value="Click Me" onclick="showValue();" />
</form>
</body>
</html>
ค่าคงที่ Infinity ทั้งสอง
| Constant | Value | คำอธิบาย |
|---|---|---|
Number.POSITIVE_INFINITY | Infinity | มากกว่าตัวเลขใดๆ |
Number.NEGATIVE_INFINITY | -Infinity | น้อยกว่าตัวเลขใดๆ |
การเกิด Infinity
1 / 0; // Infinity -1 / 0; // -Infinity Number.MAX_VALUE * 2; // Infinity -Math.pow(10, 1000); // -Infinity
การตรวจสอบ
Number.isFinite(value); // false ถ้าเป็น Infinity value === Infinity; // true ถ้าเป็น +Infinity value === -Infinity; // true ถ้าเป็น -Infinity Math.abs(value) === Infinity; // true ทั้งคู่
คุณสมบัติทางคณิตศาสตร์
Infinity + 1 = InfinityInfinity * 2 = InfinityInfinity / Infinity = NaNInfinity - Infinity = NaN1 / Infinity = 0