[X]

Negative Zero

luljs still works

Zero and minus zero are equal, until they are not.

In 2026: Still works. Floating point has a separate -0. It equals 0 under both == and ===, so it usually hides. But Object.is tells them apart, and dividing by it reveals the sign: 1 / -0 is -Infinity. Math.round(-0.5) returns -0 for exactly this reason.

Where it came from: IEEE 754 gives zero a sign. Kyle Simpson's You Don't Know JS covers where -0 hides and how Object.is exposes it. You Don't Know JS

<script>
document.write('<p><code>0 === -0</code> is <b>' + (0 === -0) + '</b></p>');
document.write('<p><code>Object.is(0, -0)</code> is <b>' + Object.is(0, -0) + '</b></p>');
document.write('<p><code>1 / -0</code> is <b>' + (1 / -0) + '</b></p>');
</script>
sandboxed demo · breaks nothing but itselfrestart

More in luljs

all 63 in luljs › · the whole library ›