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?
- 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 returnfalse
. – cookie monster Commented Feb 4, 2014 at 18:56 -
Fun fact:
isFinite(null)
returnstrue
. – EfrainReyes Commented Mar 10, 2014 at 18:42 -
@EfrainReyes Yes, because
Number(null) === 0
. :-) – Ionică Bizău Commented Mar 10, 2014 at 19:46
5 Answers
Reset to default 9As 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
评论列表(0条)