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

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744218420a4563663.html

相关推荐

  • javascript - Why isn&#39;t NaN finite? - Stack Overflow

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

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信