Infinity

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

全局属性 Infinity 是一个数值,表示无穷大。

尝试一下

const maxNumber = Math.pow(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全局对象global object)的一个属性,即它是一个全局变量。

Infinity 的初始值是 Number.POSITIVE_INFINITYInfinity(正无穷大)大于任何值。

该值的意义与数学无穷大略有不同。有关详细信息,请参见 Number.POSITIVE_INFINITY

示例

js
console.log(Infinity); /* Infinity */
console.log(Infinity + 1); /* Infinity */
console.log(Math.pow(10, 1000)); /* Infinity */
console.log(Math.log(0)); /* -Infinity */
console.log(1 / Infinity); /* 0 */
console.log(1 / 0); /* Infinity */

规范

Specification
ECMAScript® 2025 Language Specification
# sec-value-properties-of-the-global-object-infinity

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
Infinity

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

参见