Hacker News new | ask | show | jobs
by xyclos 3246 days ago
NaN is meant to represent a non-sensical mathematical operation (like divide by 0). One non-sensical mathematical operation is not the same as some other non-sensical mathematical operation (1/0 !== Infinity/Infinity)
4 comments

That's a good point, a lot of this seems like it can be explained with some context or just asking why you'd ever want to do that.
>NaN is meant to represent a non-sensical mathematical operation

This is not a very good explanation. NaN is used to represent a nonsensical value. By your explanation (1/0 === 1/0) should be true since they represent the same invalid opperation. The fact that NaN != NaN is not meant to mean anything, it is merely defined that way to prevent a class of bugs from occurring. Anyone not familiar with the definition is correct to be confused by it. I'd think if the spec was designed today, this special case (hack) wouldn't be there and we'd have exceptions in its place.

Nor is it the same as the same non-sensical mathematical operator :-)

1/0 !== 1/0

That's mad. In JS, 1/0 is Infinity, not Undefined. And Infinity is not equal to itself.
That's a good explanation, thanks.