<分区>
NaN 代表非数字。
看起来 angular.isNumber 认为它是一个数字。 ( Angular 1.4.2) 为什么 angular.isNumber 对于 NaN 输入返回 true?
谢谢
<分区>
NaN 代表非数字。
看起来 angular.isNumber 认为它是一个数字。 ( Angular 1.4.2) 为什么 angular.isNumber 对于 NaN 输入返回 true?
谢谢
最佳答案
引用 IgorMinar , Angular Developer 在这个确切的 question :
$ node > typeof NaN 'number'
It kind of makes sense if you squint with both eyes and plug your ears.
If you deliberately use NaN in your app, you should use isNaN instead of angular.isNumber.
I'm inclined to say that the current behavior, even though a bit surprising, is consistent with how NaN is being treated in javascript. If you have some good arguments for changing the behavior please share them with us.
所以问题真正针对的是 javascript 标准本身,而不是 Angular
要回答这个问题,我们必须转到 ECMAScript 5 specification of number type ,当然它说:
4.3.20 Number type
set of all possible Number values including the special “Not-a-Number” (NaN) values, positive infinity, and negative infinity
4.3.23 NaN
number value that is a IEEE 754 “Not-a-Number” value
所以是的,根据最新ECMAScript Specification我是一个数字
关于javascript - 为什么 angular.isNumber(NaN) 返回 true?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31485360/