4 ms·
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
by caub 10y ago
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
- Arkanum 10y agoI'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.
- kuschku 10y agoNaN === NaN evaluates to false. That’s what happens here, not anything with Infinity.
- Arkanum 10y agoYeah, that makes sense mostly. But why is NaN === NaN false? What am I missing here?
- kuschku 10y agoBecause 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.
- caub 10y agojust type them in your console instead of saying wrong things
- StyloBill 10y ago> 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.
- caub 10y agoyea 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
- deleted 10y ago[deleted]
- zghst 10y agoObject.is(a,b) end of story
- caub 10y agono, -Infinity is not Infinity