Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does angular.isNumber(NaN) return true? [duplicate]

NaN represents Not-A-Number.

It appears that angular.isNumber thinks it is a number. (angularjs 1.4.2) Why does angular.isNumber return true for NaN input?

thanks

like image 296
mduf Avatar asked Oct 23 '25 17:10

mduf


1 Answers

Quoting IgorMinar, Angular Developer in this exact 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.

So the question really goes for the javascript standard itself not for Angular

And to answer this question we must go to ECMAScript 5 specification of number type, of course it says:

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

So yes, according to the latest ECMAScript Specification i'm a number

like image 98
NaN Avatar answered Oct 26 '25 05:10

NaN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!