Reading through the ECMAScript 5.1 specification, +0
and -0
are distinguished.
Why then does +0 === -0
evaluate to true<
Answering the original title Are +0 and -0 the same?
:
brainslugs83
(in comments of answer by Spudley
) pointed out an important case in which +0 and -0 in JS are not the same - implemented as function:
var sign = function(x) {
return 1 / x === 1 / Math.abs(x);
}
This will, other than the standard Math.sign
return the correct sign of +0 and -0.