javascript - 为什么 angular.isNumber(NaN) 返回 true?

标签 javascript angularjs nan

<分区>

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/

相关文章:

javascript - 如何将页面添加到现有的 AngularJS 应用程序?

c - 将 NAN float 转换为 int 时出现问题

python - 有没有办法获得 pandas 中前两列的平均值?

c - exp() 函数不应该返回 nan

javascript - 无法再次请求全屏 chrome

java - onchange 后 Wicket 数据表更改单元格的字体或 css

javascript - 使用来自 Observable Angular 2 的数据

angularjs - 使电话号码可按 Angular 点击

javascript - 在 Datepicker 中保存 ng-change 本地范围的状态

javascript - Ajax获取外部JS而不加载它