Infinity
Infinity 全域性屬性是一個表示無窮大的數值。
試一試
const maxNumber = 10 ** 1000; // Max positive number
if (maxNumber === Infinity) {
console.log("Let's call it Infinity!");
// Expected output: "Let's call it Infinity!"
}
console.log(1 / maxNumber);
// Expected output: 0
值
與 Number.POSITIVE_INFINITY 具有相同的數值。
Infinity 的屬性特性 | |
|---|---|
| 可寫 | 否 |
| 可列舉 | 否 |
| 可配置 | 否 |
描述
Infinity 是全域性物件的屬性。換句話說,它是全域性作用域中的一個變數。
值 Infinity(正無窮大)大於任何其他數字。
此值的行為與數學上的無窮大略有不同;有關詳細資訊,請參閱 Number.POSITIVE_INFINITY。
示例
使用 Infinity
js
console.log(Infinity); /* Infinity */
console.log(Infinity + 1); /* Infinity */
console.log(10 ** 1000); /* Infinity */
console.log(Math.log(0)); /* -Infinity */
console.log(1 / Infinity); /* 0 */
console.log(1 / 0); /* Infinity */
規範
| 規範 |
|---|
| ECMAScript® 2026 語言規範 # sec-value-properties-of-the-global-object-infinity |
瀏覽器相容性
載入中…