Hacker News new | ask | show | jobs
by _getify 2639 days ago
In JS:

  -0 + 0;   // 0
  -0 + (-0);  // -0
  -0 - 0;  // -0
I claim that the `-0 + 0` case is the strange inconsistent one, so that's the reason for my WTF label.

----

Consider the counter-argument, that it's intuitive/correct because in math `X + (-X) = 0`:

  3 + (-3);   // 0
  -3 + (3);  // 0
  -0 + (0);   // 0
  0 + (-0);  // 0
It's true that this characteristic by itself is preserved, but where it falls apart:

  X + (-X) = 0    // -->
  X = 0 - (-X)   // -->
  X = 0 + X
That final statement should be true for all X, but as demonstrated above, it's not true for -0.