by Sai gowtham

How to check if a number is infinity in JavaScript

Learn, how to check if a given number is infinity or not in JavaScript.

Using the Number.isFinite() method

The Number.isFinite() method accepts the value as a argument and returns false if a value is +Infinity, -Infinity, or NaN (Not-a-Number); else it returns true.

Example:

Number.isInFinite(1/0); // false (Infinity)

Number.isInfinite(2/34); // true (finite number)

Similarly, we can also use the Global isFinite() method but it coerces the given value to a number first.

isFinite(1/'13'); // true

isFinite(3/0); // false (Infinity)

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
130,921 students enrolled
21 hours of video content
View Course