Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does -0 === 0 evaluate to true? [duplicate]

Tags:

javascript

According to what I've read, all numbers in JavaScript are saved as floats except array indexes and the operands of bitwise operations.

Because all floats have a sign bit -0 === 0 should evaluate to false. However it evaluates to true.

like image 435
arc.slate .0 Avatar asked May 03 '16 19:05

arc.slate .0


1 Answers

Because JS uses the IEEE 754 standard for floating point numbers, which states that -0 and +0 should "compare as equal with the usual (numerical) comparison operators." (source)

like image 123
ssube Avatar answered Nov 12 '22 01:11

ssube