Is the first example valid?
In MDN I read this but I did not understand it well:
NaN compares unequal (via ==, !=, ===, and !==) to any other value – including to another NaN value. Use Number.isNaN() or isNaN() to most clearly determine whether a value is NaN
Can you explain this to me in plainer words and with simple examples. Any external link is welcome.
With the first case you have, if your variable zipInt does happen to be NaN, it still wouldn’t be equal to NaN because no NaN is equal to another NaN. NaN !== NaN. You would have to use isNaN or Number.isNaN(). I know it is very weird, but it happens to be true.
NaN is the the program saying “I believe that this value should be a number, but all I know is that it isn’t a number I recognise”. The NaN value the program returns in that case can’t be equal to anything because the program can’t evaluate what it actually is. So someValue == NaN will never evaluate to true because the program cannot tell what NaN is. And NaN is not equal to NaN for the same reason.
To check is a value is NaN, you either use the Number.isNaN(someValue) function, or you can check if someValue != someValue: the only time it will not be equal to itself is if the program doesn’t know what it is, i.e. it is NaN.