node.js string.replace doesn't work?

前端 未结 4 1861
庸人自扰
庸人自扰 2021-02-02 05:12
var variableABC = \"A B C\"; 
variableABC.replace(\'B\', \'D\') //wanted output: \'A D C\'

but \'variableABC\' didn\'t change :

4条回答
  •  野性不改
    2021-02-02 06:07

    Strings are always modelled as immutable (atleast in heigher level languages python/java/javascript/Scala/Objective-C).

    So any string operations like concatenation, replacements always returns a new string which contains intended value, whereas the original string will still be same.

提交回复
热议问题