Home > Back-end >  Is it possible to change a JavaScript string? Why do we need a "string builder" in JavaScr
Is it possible to change a JavaScript string? Why do we need a "string builder" in JavaScr

Time:02-23

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

CodePudding user response:

They are immutable. You cannot change a character within a string with something like var myString = "abbdef"; myString[2] = 'c'. The string manipulation methods such as trim, slice return new strings.

In the same way, if you have two references to the same string, modifying one doesn't affect the other

  • Related