JS: Infinity

By Xah Lee. Date: . Last updated: .

What is Infinity

Infinity is the value of the property key "Infinity" of the Global Object.

Infinity is a literal value. For example, you can write let x = Infinity;

console.assert(globalThis["Infinity"] === Infinity);

Purpose of Infinity

Infinity is typically returned when divide by zero.

console.assert(1 / 0 === Infinity);

Type of Infinity

Type of Infinity is number.

console.assert(typeof Infinity === "number");

Infinity === Infinity return true.

console.assert(Infinity === Infinity);

Test Infinity

Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY

console.assert(
 Object.is(Number.POSITIVE_INFINITY, Infinity),
);

console.assert(
 Object.is(Number.NEGATIVE_INFINITY, -Infinity),
);

console.assert(
 Number.POSITIVE_INFINITY === Infinity,
);

console.assert(
 Number.NEGATIVE_INFINITY === -Infinity,
);