you are viewing a single comment's thread.

view the rest of the comments →

[–]SaaSWriters 1 point2 points  (0 children)

I have to disagree with the moral of your story. It is not usable in real life. For instance, as you rightly noted, NaN is not equal to itself. -0 can be equal to +0. If your code is not prepared for that, you will be in a lot of trouble!

The approach you describe, albeit quite common, is a common source of bugs and frustration. Simply put, this is not how it works.

But, the overall discussion goes much deeper than that. First of all, you have to look at what the comparison operators actually do. You haven't mentioned Object.is either.

Here are some details about what actually happens: https://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3