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

Added "NaN is not NaN" #375

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

shreyas-a
Copy link

No description provided.

@@ -63,6 +65,17 @@ Here, both operators compare for **identity** and **not** equality; that is, the
will compare for the same **instance** of the object, much like `is` in Python
and pointer comparison in C.

### Comparing NaN
If either side of double equals `a == b` contains `NaN`, `false` will be returned.
In case of a tripple equals `a === b`, following things are considered.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo triple

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -63,6 +65,17 @@ Here, both operators compare for **identity** and **not** equality; that is, the
will compare for the same **instance** of the object, much like `is` in Python
and pointer comparison in C.

### Comparing NaN
Copy link
Collaborator

@peterjwest peterjwest Oct 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure about this explanation, according to my testing and research any equality with NaN, double or triple, returns false.

I would suggest an alternate explanation:

Any equality comparison with `NaN` will return `false`. This includes comparing `NaN` with itself, making it the only value in JavaScript which doesn't equal itself.

I don't think it's relevant here to talk about the type of NaN, although that should probably be added in the typeof section.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've referred to this ecma standards explanation

@timruffles
Copy link
Collaborator

timruffles commented Oct 10, 2017

Great start, but I think currently this isn't thorough enough to be helpful.

First - it could explain why NaN !== NaN: to avoid two nonsensical operations being equal to each other, e.g if(Math.log(-1) === parseInt("%")) { doBadThing() }. Secondly it could mention the isNaN() function, which is the correct way to check for NaN.

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

Successfully merging this pull request may close these issues.

3 participants