by tedunangst · 3y ago · 0 comments
Sometimes it seems javascript has a mind of its own, and turns all my numbers into strings when I'm not looking, so I have to sprinkle x = x | 0 throughout the code, like hanging garlic.
It seems to me like those two things are orthogonal. (Not that JS wouldn't necessarily be nicer with a separate concatenation operator.)
const y = +x + 12;
Will be number addition even if x is a string.
const y = Number(x) + 12
Depending on your audience, that might be clearer in intent than `+x`.