此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
Infinity
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
Infinity 全域屬性是一個代表無限大的數值。
嘗試一下
const maxNumber = 10 ** 1000; // 最大正數
if (maxNumber === Infinity) {
console.log("我們稱之為無限大!");
// 預期輸出:「我們稱之為無限大!」
}
console.log(1 / maxNumber);
// 預期輸出: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 */
規範
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-value-properties-of-the-global-object-infinity> |
瀏覽器相容性
Loading...