Wrong "Math"
Looks like today math wouldn’t be on our side:
let a = 0;
a += "-1" < "-2" // a = 1Explanation
Actually, there is nothing wrong with math — we got this because of string compare:
- Strings in JS are compared character by character. If symbols codes are equal - next pair is selected (there are additional rules but now they won’t help us).
- When we compare
"-1"and"-2"comparator skips first symbol and compare'1'with'2'. Of course'1'is less than'2'. - In result, it will return
truewhich is equal to1when we add it to variable. - Done!