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 |
浏览器兼容性
加载中…