For example, why would you expect `Boolean("false")` to equal `false`? It's a string, and bears no relation to the Boolean type. [0]
For example, why would you expect `Boolean("false")` to equal `false`? It's a string, and bears no relation to the Boolean type. [0]
[1, 2, 3] + [4, 5, 6] == "1, 2, 34, 5, 6"
or parseInt(0.000001) == 0
parseInt(0.0000001) == 1
or "" + 5 == "5"
"" - 5 = -5Well, `+` is a string operator. There's no infix array concatenation operator, so makes sense.
> parseInt(0.000001) == 0 > parseInt(0.0000001) == 1
Never knew about this one! Quite funny actually and I'm curious why that happens. I suppose because `0.0000001` is represented as an exponent rather than a decimal? Although I haven't seen `parseInt` used since 2015, you should use `Number`.
> "" + 5 == "5" > "" - 5 = -5
iirc
`+` operator: - If LHS is a string, concatenate - Otherwise, cast to Number and perform arithmetic.
`-` operator: - Perform arithmetic.
All of these are explainable, and never catch anybody competent out in practice. And, since TypeScript is the norm in a lot of places now, it's never an issue.
The name parseInt suggests it takes a string. Especially "" - 5, why?
They each have different quirks (some will parse 'a123' as 123, others will handle scientific notation etc). The only reliable way of doing this is doing a regex followed by parseInt... which is definitely a footgun IMO.