Does javascript have the concept of negative zero

Consider the following

var l = console.log.bind(console); l(-0); // 0 l(0); // 0 l(0 === -0); // true l(0 == -0); // true l(1 / 0); // Infinity l(1 / -0); // -Infinity 
  • Why is negative zero equal to zero?
  • Given this, why does he behave differently?

Bonus question:

  • Is the 0 / -0 combination the only one in which identical objects behave differently?

I know that NaN / NaN is a combination in which unequal objects behave the same.

+6
source share
1 answer

Why is negative zero equal to zero?

Because IEEE 754 requires it .

Is the 0 / -0 combination the only one in which identical objects behave differently?

I think so. In Javascript, only Numbers have a special algorithm === , and 0, -0, NaN are the only special cases (ECMA-262 ยง11.9.6).

+7
source

Source: https://habr.com/ru/post/893451/


All Articles