var str = \"This is a string\";
var thing = str.replace(\"string\",\"thing\");
console.log( str )
>> \"This is a string\"
console.log( thing )
>> \"Th
There is a reason why strings are immutable. As Javascript use call-by-sharing technic, mutable string would be a problem in this case :
function thinger(str) {
return str.replace("string", "thing");
}
var str = "This is a str";
var thing = thinger(str);
In this situation you want your string to be passed by value, but it is not. If str was mutable, thinger would change str, that would be a really strange effect.