最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why isn't NaN finite? - Stack Overflow

programmeradmin6浏览0评论

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?

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?

Share Improve this question asked Feb 4, 2014 at 18:46 Ionică BizăuIonică Bizău 114k94 gold badges310 silver badges487 bronze badges 5
  • 5 It's not a number. That seems more like infinity than a number, which isn't. – Dave Newton Commented Feb 4, 2014 at 18:47
  • 3 @MarkLinus the NaN constant represents nonsense bit arrangements in floating point values. Because it's "not a number", it cannot have any properties that numbers can have. It's not finite, and it's also not infinite. It's not even, and it's not odd. It's not positive, and it's not negative. It's not a number :) – Pointy Commented Feb 4, 2014 at 18:48
  • 1 If there was an isInfinite() method, it too would return false. – cookie monster Commented Feb 4, 2014 at 18:56
  • Fun fact: isFinite(null) returns true. – EfrainReyes Commented Mar 10, 2014 at 18:42
  • @EfrainReyes Yes, because Number(null) === 0. :-) – Ionică Bizău Commented Mar 10, 2014 at 19:46
Add a ment  | 

5 Answers 5

Reset to default 9

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/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN
  • https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite

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

The result of any arithmetic operation on NaN is NaN.

The result of any logic operation on NaN is false.

Because an infinite number... is still a number. NaN isn't a number in any possible sense.

It's like an error in Matrix.

Finite means capable of being counted. It has to return true or false for isFinite. I think it makes more sense for NaN to be infinite.

发布评论

评论列表(0)

  1. 暂无评论