Skip to content

Added "NaN is not NaN"#375

Closed
shreyas-a wants to merge 2 commits intoBonsaiDen:masterfrom
shreyas-a:master
Closed

Added "NaN is not NaN"#375
shreyas-a wants to merge 2 commits intoBonsaiDen:masterfrom
shreyas-a:master

Conversation

@shreyas-a
Copy link
Copy Markdown

No description provided.

Comment thread doc/en/types/equality.md Outdated

### 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
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

Comment thread doc/en/types/equality.md
will compare for the same **instance** of the object, much like `is` in Python
and pointer comparison in C.

### Comparing NaN
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@shreyas-a shreyas-a closed this Aug 31, 2025
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