JS: String is Immutable
String is Immutable
JavaScript string is immutable. That means, any time you join string or get a substring or replace parts of the string, a new string is created.
All JavaScript string operators and methods return a new string.
The longer the string, the most costly is to recreate the string.
In practice, this means, do not edit long string, especially not in a loop. When you have a long string, such as a file content, split it into array, edit the array, then at the end convert the array back to a string.