Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't NaN finite?

Tags:

javascript

nan

Testing the isFinite function I see that NaN is an infinite number (even if it's not a number :-)).

isFinite(NaN) // returns false

What's the logic behind this? Why isn't NaN finite?

like image 561
Ionică Bizău Avatar asked Dec 19 '22 18:12

Ionică Bizău


2 Answers

As Dave Newton said, NaN is not a number, and then you have to consider that it isn't finite nor infinite. The same occurs to these:

NaN > 0  // false
NaN < 0  // false

You might want to read these articles:

  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite
like image 85
Danilo Valente Avatar answered Jan 11 '23 14:01

Danilo Valente


Because it is not a numeric value...and finite/infinite is applicable only to numbers.

like image 34
Ashok Kumar Gupta Avatar answered Jan 11 '23 13:01

Ashok Kumar Gupta