Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

var a = 0; var b = -0;

console.log(a === b) // true

console.log(1/a === 1/b) // false

That's perfect math you mean, of course -Infinity != Infinity, what did you expect?

I think you should rather think harder, learn math possibly, and your 'safety' problems with arrays are not problems at all, it's the opposite for other people



> I think you should rather think harder, learn math possibly

Oh the irony, when stating that 1/0 = infinity. If you'd learn maths yourself, you'd know that 1/0 is undefined.


yea 1/x is not strictly defined for x=0, but you can extend it in ℜ ∪ {+∞,-∞}, I don't know your math background, but 1/-0 could make you think of limits:

1/0 is like 1/0⁺ (limit of 1/x in ]0,+∞[ when x->0) == Infinity.

1/-0 is like 1/0⁻ (limit of 1/x in ]-∞,0[ when x->0) == -Infinity.

1/Infinity is 0 ....

0/0 is however an indefinite form, so it's NaN

so the behavior of JS makes sense

And even if 1/0 and 1/-0 returned NaN, they wouldn't be equal to each other too


I'm not sure that's right. 1/0 is undefined NOT infinity, hence -1/0 is also undefined. So actually line 3 should evaluate as true.


NaN === NaN evaluates to false. That’s what happens here, not anything with Infinity.


Yeah, that makes sense mostly. But why is NaN === NaN false? What am I missing here?


Because there is many ways NaN can be generated, all very different.

== is only defined for numbers, too.

1/0 and 50/0 aren’t the same, for example.


just type them in your console instead of saying wrong things


Then they don’t conform to the IEEE standards, and the Javascript implementers are wrong.


NaN !== NaN is just right


Yes, but 1/0 === Infinity isn’t. That number is very different from Infinity.


Object.is(a,b) end of story


no, -Infinity is not Infinity




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: