Javascript String Assignment Operators

后端 未结 6 510
执笔经年
执笔经年 2021-01-17 17:12

How come I can use += on a string, but I cannot use -= on it?

For example...

var test = \"Test\";
var arr = \"⇔\"         


        
6条回答
  •  梦毁少年i
    2021-01-17 17:26

    That's because the minus sign is not a valid String operator, whereas the plus sign is overloaded to handle both Numbers (addition operator) and Strings (concatenation operator).

    What results were you hoping to get from this?

提交回复
热议问题