3 ms·
> after all, a 1 is a 1 even if it happens to be a string Is it? In JS: "1" + 1 == "11"; 1 + 1 == 2
by viraptor 15y ago
> after all, a 1 is a 1 even if it happens to be a string
Is it? In JS: "1" + 1 == "11"; 1 + 1 == 2
- tikhonj 15y agoThe problem there isn't with coercion, it's with + being both addition and concatenation, as I mentioned at the end of my comment. If you use any other operator (any reasonable operator), it works: "1" - 1 === 0, "1" - "1" === 0 and 1 - 1 === 0.