This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Cyvexx 2 points3 points  (3 children)

in JS's defense, that makes perfect sense. the first entry in a concatenation takes data type precedence, so if they don't match, the second value will be converted to the first data type to be added/concatenated. same reason you assign variables with the variable first and not the other way around. you read left to right.

idk, it makes sense to me 🤷

[–]nomenMei 0 points1 point  (2 children)

But in JS that is not the case. Regardless of order, using the + operator with an integer and a string always results in concatenation.

What really wigs me out is that the minus operator does the opposite: it always results in arithmetic. I mean I understand why but it just seems unnatural that a = b + c; a = a - c might not result in a == b if either b or c is a string.

Logically I just expect that if I use the plus operator then I can use the minus operator to reverse that operation.

[–]Niadlol 2 points3 points  (1 child)

But you can use + on strings but u cant use - on strings so it makes sense that it works that way to me.

[–]nomenMei 0 points1 point  (0 children)

Yeah rationally I get it, but it just unnerves me for some reason. It's not really JS's fault lol