JavaScript adding a string to a number

后端 未结 8 732
轮回少年
轮回少年 2020-11-29 04:12

I was reading the re-introduction to JavaScript on MDN and in the section Numbers it said that you can convert a string to a number simply by adding a plus operator

8条回答
  •  借酒劲吻你
    2020-11-29 04:38

    It is confusing, but binary + seems to be a rare case of a number being coerced to a string. In most cases it would be the other way round (so it's very easy to think that you don't need to be too fussy about the type)

    4+"3" = "43"

    4-"3" = 1

提交回复
热议问题