Why isn't NaN finite?

丶灬走出姿态 提交于 2019-12-01 05:27:29

问题


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?


回答1:


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



回答2:


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




回答3:


The result of any arithmetic operation on NaN is NaN.

The result of any logic operation on NaN is false.




回答4:


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

It's like an error in Matrix.




回答5:


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.



来源:https://stackoverflow.com/questions/21560812/why-isnt-nan-finite

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!