When I posted the NaN article on facebook in a programmers group, I received some very bad reviews. Let's analyze them.
"It is obvious!"
It is obvious, but it's not common. Partly because I am a developer with some years of experience and, altough I have studied and studying a lot of programming, I have never occourred in
Why NaN === NaN is false
The fact that
NaN !== NaN is true is obvious, after you reason about it.
When I thought of this the first time, I thought it's absurd, but after a while I realized that this is the only possible logic behaviour. As some have said, if I divide a number by a string I get
NaN, and if I divide another number by another string I get another
NaN. Are these two
NaN equal? no.
NaN is not even a measurable property.
NaN is a state, and as such it cannot be compared to other
Why this is not a JS-only matter
Division of zero by zero
Dividing an infinity by an infinity
Multiplication of an infinity by a zero
Any operation in which NaN is an operand
Converting a non-numeric string or undefined into a number
It is described in standard IEEE 754, from 1985. In this standard you can read how integer and decimal numbers are stored inside a computer (spoiler: decimal numbers in a computer are not real, continuous, neither infinite). You'll read of many edge cases regarding decimal numbers, along with what should happen when you're in one of the cases described before. So,
NaN is a convention followed by pretty much every programming language.
But JS does some stranger things.
It has two
isNaN()functions, and you must choose the one you need carefully.
isNaN()function does type cohercion, that's why
isNaN(null) == false.
Should every developer in the world know this? Yes, but chances are that you'll never need to use this bit of information.
Is this a good question in a job interview? Well, I don't think so.
Chances are that you'll never need to do this, and even if you hit
NaN, that's something you'll learn in two hours wikipedia's reading (or my blog, hehehe).
In a Job interview I would focus on what the candidate can actially do and his way of reasoning.
Of course, if I'm interviewing for a position that has to deal with financial or mathematical programming, knowing of
Is it dumb to explore these areas of a programming language?
In my opinion, no. It's just fun, and a new way to learn something.
In some very bad comments (ones that started with "you are idiot") there were some insightful hints that made me follow links, read articles, study more - and write this.
But on the web I have received some critics like "buy a book and read it", and the first thing I thought is ... haters' gonna hate.
Others have also accused me of "plagiarism" :D
Honestly, this happens in every group that has more than 1-2 thousand members; people will comment out just to say that you're dumb and they're better.