# JavaScript — Check if a Number Is Infinity

We recently worked on an audio player in a web application. The player uses a streaming server to play tracks. For example, a track can be a radio song, a podcast episode, or an endless radio stream.

An audio track and podcast episodes are finite. Finite tracks should use a progress bar to show the listening time. But the progress bar should not be visible for endless radio streams. And radio streams have a duration of „infinity“.

This tutorial shows you how to detect whether a given number is (positive or negative) infinity.

## Detect if a Number Evaluates to Infinity

JavaScript’s global `Number` object provides a handful of static methods. One of these methods is `Number#isFinite` determining whether a given number is finite or not. You can use this helper method to constructor your own `isInfinity` method like this:

``````/**
* Determine whether the given `number` evaluates to infinity.
*
* @param {any} number
*
* @returns {Boolean}
*/
function isInfinity(number) {
return !Number.isFinite(number)
}
``````

Then use your `isInfinity` helper method to detect whether a number equals infinity:

``````isInfinity(1 / 0)
// true

isInfinity(10 / 2)
// false

isInfinity(0 / 0)
// true
``````

## Positive or Negative Infinity

You may also distinguish between positive and negative infinity. JavaScript’s global `Number` object provides constants you can use for comparison:

``````const isPositiveInfinity = (1 / 0) === Number.POSITIVE_INFINITY
// true

const isPositiveInfinity = (-1 / 0) === Number.POSITIVE_INFINITY
// false

const isPositiveInfinity = (-1 / 0) === Number.NEGATIVE_INFINITY
// true
``````

Enjoy infinity!

# Explore the Library

Find interesting tutorials and solutions for your problems.