Are JavaScript strings immutable? Do I need a “string builder” in JavaScript?

后端 未结 10 2661
挽巷
挽巷 2020-11-22 02:48

Does javascript use immutable or mutable strings? Do I need a \"string builder\"?

10条回答
  •  半阙折子戏
    2020-11-22 03:32

    Strings are immutable – they cannot change, we can only ever make new strings.

    Example:

    var str= "Immutable value"; // it is immutable
    
    var other= statement.slice(2, 10); // new string
    

提交回复
热议问题