🌐
W3Schools
w3schools.com › jsref › jsref_isfinite_number.asp
JavaScript Number.isFinite() Method
The Number.isNaN() Method · The POSITIVE_INFINITY Property · The NEGATIVE_INFINITY Property · isFinite() returns true if a value is a finite number. Number.isFinite() returns true if a number is a finite number.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › isFinite
isFinite() - JavaScript - MDN Web Docs - Mozilla
July 8, 2025 - The isFinite() function determines whether a value is finite, first converting the value to a number if necessary. A finite number is one that's not NaN or ±Infinity. Because coercion inside the isFinite() function can be surprising, you may prefer to use Number.isFinite().
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number › isFinite
Number.isFinite() - JavaScript - MDN Web Docs
July 10, 2025 - The Number.isFinite() static method determines whether the passed value is a finite number — that is, it checks that a given value is a number, and the number is neither positive Infinity, negative Infinity, nor NaN.
🌐
W3Schools
w3schools.com › jsref › jsref_isfinite.asp
JavaScript isFinite() Method
The isFinite() method returns true if a value is a finite number.
🌐
W3Schools
w3schools.com › python › ref_math_isfinite.asp
Python math.isfinite() Method
The math.isfinite() method checks whether a number is finite or not. This method returns True if the specified number is a finite number, otherwise it returns False. ... If you want to use W3Schools services as an educational institution, team ...
🌐
W3Schools
www-db.deis.unibo.it › courses › TW › DOCS › w3schools › jsref › jsref_isfinite_number.asp.html
JavaScript Number isFinite() Method
Number.isFinite() does not convert the values to a Number, and will not return true for any value that is not of the type Number. ... Color Converter Google Maps Animated Buttons Modal Boxes Modal Images Tooltips Loaders JS Animations Progress Bars Dropdowns Slideshow Side Navigation HTML Includes ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-number-isfinite-method
JavaScript Number isFinite() Method - GeeksforGeeks
August 8, 2023 - The Number.isfinite() method is different from the isfinite() method since this method doesn’t forcibly convert the parameter to a number and it does not return true for any value that is not of the type number.
🌐
DEV Community
dev.to › kobbyowen › javascript-in-depth-isfinite-isnan-functions-cp6
JavaScript In Depth - isFinite & IsNaN Functions - DEV Community
November 1, 2021 - This behavior is so true that, ECMAScript documentation suggests that one of the reliable ways to check for NaN is the expression(x === x), which returns false only if x is a NaN. Mostly, to determine if a number is okay to be used in arithmetic operation without few surprises, you should find yourself using isFinite more than isNaN, since isFinite checks for NaN values and goes on to check for infinite values.
Find elsewhere
🌐
Educative
educative.io › answers › what-is-numberisfinite-in-javascript
What is Number.isFinite() in JavaScript?
August 20, 2021 - The Number.isFinite method returns true if the number passed is a finite number; otherwise, it returns false.
🌐
Educative
educative.io › answers › what-is-the-numberisfinite-method-in-typescript
What is the Number.isFinite() method in TypeScript?
In TypeScript, the Number.isFinite() method of the Number class is used to check if a certain number is finiteA finite number is a number that is measurable or countable · Note: TypeScript is the superset of JavaScript.
🌐
Code.mu
code.mu › en › javascript › manual › lang › isFinite
The isFinite function - a number checking in JavaScript
The isFinite function checks if a parameter is a finite number (that is, not a string, array, etc., and not plus or minus infinity).
🌐
Cach3
w3schools.com.cach3.com › jsref › jsref_isfinite_number.asp.html
JavaScript Number isFinite() Method
Number.isFinite() does not convert the values to a Number, and will not return true for any value that is not of the type Number. ... Tabs Dropdowns Accordions Side Navigation Top Navigation Modal Boxes Progress Bars Parallax Login Form HTML Includes Google Maps Range Sliders Tooltips Slideshow ...
🌐
Cppreference
en.cppreference.com › w › cpp › numeric › math › isfinite
std::isfinite - cppreference.com
March 21, 2023 - The additional overloads are not required to be provided exactly as (A). They only need to be sufficient to ensure that for their argument num of integer type, std::isfinite(num) has the same effect as std::isfinite(static_cast<double>(num)).
🌐
GitHub
github.com › 30-seconds › 30-seconds-of-code › issues › 41
Validate number: use only isFinite? · Issue #41 · Chalarangelo/30-seconds-of-code
December 12, 2017 - Validate number Use !isNaN in combination with parseFloat() to check if the argument is a number. Use isFinite() to check if the number is finite. const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n); // validateNumber('10') ...
Author   Chalarangelo
🌐
Edgecompute
js-compute-reference-docs.edgecompute.app › number() constructor › number.isfinite()
Number.isFinite() | @fastly/js-compute
The Number.isFinite() method determines whether the passed value is a finite number — that is, it checks that a given value is a number, and the number is neither positive Infinity, negative Infinity, nor NaN · The boolean value true if the given value is a finite number. Otherwise false
Top answer
1 of 3
13

Number.isFinite() is not a type guard because it can lead to weird and wrong behaviour in edge cases.

Number.isFinite(4) -> true and the value is a number. That's fine.
Number.isFinite("apple") -> false and the value is not a number. That's fine.
Number.isFinite(Infinity) -> false but the value is not not a number. That's not good.

Some things in JavaScript are of type number but are not finite. These are the values Infinity, -Infinity and NaN. Yes, it stands for "not a number" but it's of type number. It's confusing but makes sense.1

In most cases, we don't care about these non-finite values.

However, as they are still numbers, they are valid in mathematical operations. The concept of infinity is also mathematical and sometimes can be useful.

Discarding these values leads to sometimes wrong code. Let's assume that Number.isFinite() was declared as a type guard. Then consider this code:

function atLeast(minValue: string | number, num: number): boolean {
    const min: number = Number.isFinite(minValue)
        ? minValue
        : Number(minValue.replace(/\D/g, "")); //convert
    
    return num >= min;
}
atLeast(2, 42);            //true
atLeast("$3.50", 42);      //true
atLeast(-Infinity, 42);    //error

This would be valid code. Wrong logic and a bit weird but it's here to just illustrate a point. Still, a more realistic usage might be:

let dynamicMinimum = -Infinity; //allow all
/* ... */
someArray.filter(x => atLeast(dynamicMinimum, x));

The code in the function is accepted by TypeScript and when Number.isFinite() returns false type narrowing would cause minValue would not be considered a number and only allowed to be treated as a string by the compiler.

While the example here is contrived and not too hard to figure out it's wrong, you can easily get into a real world situation where you accidentally narrow a value out of being a number when it's still a number. This would be why Number.isFinite() is not a type guard - it can erroneously assert something about a type that is misleading.


1 Here is what I hope is an intuitive explanation why NaN is a number type. In JavaScript values can be changed and some mathematical operations need a number to work with, otherwise they make no sense. But not everything converts to a number. So when you convert a value to a number, you need to somehow signify that it cannot be converted. This is where NaN comes in.

Since the contextual information for what NaN was before conversion, you cannot definitely say it's equal to anything, hence why NaN == NaN is false. An equivalent code might be Number("apple") == Number("orange") - the two values are clearly not equal before the conversion.

2 of 3
8

First some background. On first glance, this seems to be related to the difference in JavaScript between

isFinite

which will first convert its argument to number and

Number.isFinite

which happily accepts all arguments, regardless of type, and simply returns true only for finite numbers (with no implicit conversions). In TypeScript these have signatures

function isFinite(number: number): boolean

(method) NumberConstructor.isFinite(number: unknown): boolean

In the second method, the parameter type is unknown instead of number. The reason is that in JavaScript, Number.isFinite happy returns false for non-numbers (whereas isFinite coerces first).

> Number.isFinite(false)
false
> isFinite(false)
true
> Number.isFinite(Symbol(2))
false
> isFinite(Symbol(2))
Uncaught TypeError: Cannot convert a Symbol value to a number at isFinite (<anonymous>)

Now since Number.isFinite is already expected to accept all arguments from any type and return false no matter how wacky the arguments, it makes sense for this behavior to be preserved in TypeScript. Hence the parameter type properly is unknown. For the global isFinite which is intended to work only on numbers (and does the coercion that TypeScript helps us avoid), it makes sense to restrict the parameter to being a number.

But as your question rightly asks, why, given that Number.isFinite will accept any arguments and return true only for numbers, why can't it be a type guard? The reason is that it returns true for some, but not all numbers! Let's try at least to write our own guard:

function numberIsFinite(n: any): n is number {
    return Number.isFinite(n)
}

and these make sense:

console.log(numberIsFinite(20)) // true
console.log(numberIsFinite(Number.MAX_VALUE)) // true
console.log(numberIsFinite(undefined)) // false
console.log(numberIsFinite("still ok")) // false

But here is where things go wrong-ish:

console.log(numberIsFinite(Infinity)) // false but uh-oh
console.log(numberIsFinite(NaN)) // false but uh-oh

Now it's true that with this type guard that

const x: number|string = 3
if (numberIsFinite(x)) {
  console.log(`A number whose type is ${typeof(x)}`)
} else {
  console.log(`A string whose type is ${typeof(x)}`)
}

will print

"A number whose type is number" 

so far so good but:

const x: number|string = Infinity
if (numberIsFinite(x)) {
  console.log(`A number whose type is ${typeof(x)}`)
} else {
  console.log(`A string whose type is ${typeof(x)}`)
}

will print

"A string whose type is number" 

And this is silly.

If there was a dependent type in TS called "finite number" then (and perhaps only then) would making Number.isFinite a type guard make sense.

Credit to @VLAZ, whose answer this explanation is based on. I added the second part to my original answer after reading theirs.

🌐
John Kavanagh
johnkavanagh.co.uk › home › articles › number.isnan(), number.isfinite(), and number.isinteger() in javascript
Number.isNaN(), Number.isFinite(), Number.isInteger() | John Kavanagh
May 14, 2026 - JavaScript number handling becomes much easier once you stop assuming every "number check" works the same way · That assumption causes a lot of confusion because older global functions such as isNaN() and isFinite() do a surprising amount of coercion. In other words, they often answer a slightly ...