4 ms·
Lua has a feel very much like javascript, but is much less conversion happy. It helps that there's separate operators for addition and concatenation, so you won
by tedunangst 3y ago
Lua has a feel very much like javascript, but is much less conversion happy. It helps that there's separate operators for addition and concatenation, so you won't get 1 + 2 = 12 unless you ask for it.
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.
- pleoxy 3y agoYou can convert to a number with a + before your variable. const y = +x + 12; Will be number addition even if x is a string.
- WorldMaker 3y agoOr via the Number constructor: const y = Number(x) + 12 Depending on your audience, that might be clearer in intent than `+x`.
- WorldMaker 3y agoPHP also uses different operators for addition and concatenation, but I feel that it has just as much, if not more, implicit conversion weirdness as JS. It seems to me like those two things are orthogonal. (Not that JS wouldn't necessarily be nicer with a separate concatenation operator.)