Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is.number(NaN) returning true #104

Closed
eriklharper opened this issue Mar 26, 2015 · 4 comments
Closed

is.number(NaN) returning true #104

eriklharper opened this issue Mar 26, 2015 · 4 comments
Labels

Comments

@eriklharper
Copy link

Not sure why, but that is what is happening:

image

Running 0.4.0 of is_js

@didxga
Copy link

didxga commented Mar 27, 2015

Hi @eriklharper, I think this has been fixed. Please check the latest version.

@jonhester
Copy link
Contributor

#72 I actually fixed this last month.

console.log(typeof NaN) 
// number

It was decided that even though javascript considers NaN a number it goes against the point of the check so it now returns false for NaN.

@ekaradon
Copy link

Could you please also change then the return of is.nan?
Today, is.nan(null) return false, which means that null is considered as a number by the language. It is because javascript evaluated everything false as "0".
So you will always have values considered as number through NaN() when it is null, false or empty string.
I think the library is should remove this inconsistency from the language.

@ironmaniiith
Copy link
Collaborator

@ekaradon
For your statement, "is.nan(null) return false, which means that null is considered as a number by the language"

If is.nan returns false on something, that does not mean that it has to be a number.
NaN in javascript is a predefined keyword, which is neither equal to null, nor undefined and not even itself (yes..!!). But still, it is a number.
Hence it is correct if is.nan returns false for null.

console.log(NaN == NaN)
// false

Also is.nan will "only" return true when the argument passed is not equal to itself (to keep it simple, when NaN is passed as argument).
Hope that helps. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants