Hacker News new | ask | show | jobs
by oliverkyss 3534 days ago
Why would that be surprising? NaN as a result definitely means that you cannot multiply array by object in JS either. JavaScript uses IEEE 754 special values, not exceptions on arithmetic errors (eg 1/0 returns Infinity instead of throwing). If you bother to learn the language, it doesn't surprise you.
1 comments

The problems start when you notice that your untyped key-value store has a bunch of NaNs where you were expecting a number. At this point, all you can do is pray that those numbers weren't very important, in the grand scheme of things.
So when you do calculations with important numbers, you just push the results to the store without checking them and hope for the best? NaNs can happen in any language with floats, it's just that some languages also use exceptions in some situations.
You can check the result of every operation manually but it saves you time when the language does it.