DEV Community

Discussion on: Today I answered a question which has been bothering me for a long time.

Collapse
 
kallmanation profile image
Nathan Kallman

And "11" - 0 + 1 yields 12 while "11" + 1 - 0 yields 111 ... order of operations can be important!

Collapse
 
zunamidev profile image
zunami

If we calculate ("11" - 0) we get a number again and then if we add 1 we have not anymore the string case. On the other example with ("11" + 1) here we have the case with string join and then it joins if we subtract it by 0 it will be the same but if we subtract it with a different number it will be converted into a number. But yes you are right its important to check the order of operations. The explanation is just for those who don't understand it.