Adding and subtracting strings and numbers in Javascript - auto type conversion?

前端 未结 5 1815
抹茶落季
抹茶落季 2020-12-04 01:52

Let\'s look at the following Javascript code.



        
5条回答
  •  执念已碎
    2020-12-04 02:24

    + is used for both concatenation and addition, but when used with a string, defaults to concatenation. - cannot be used on strings, so its operands are converted to numbers.

    Edit: This is not meant to be identical to the above post! XD

提交回复
热议问题