String
in Javascript is immutable, it is a true statement. So, you are correct.
So, the value of the string is immutable but not it's prototype
. String inherited the prototype
from its parent object. The functions available in the prototype do not modify the value of string, it returns a new instance of string.
When it comes to inheritance, JavaScript only has one construct:
objects. Each object has a private property which holds a link to
another object called its prototype. That prototype object has a
prototype of its own, and so on until an object is reached with null
as its prototype. By definition, null has no prototype, and acts as
the final link in this prototype chain.
The value of string in javascript is loosely coupled with prototype. If you replace the prototype of string with empty object, there will be no change of the value. You will get the exactly same value for the string when you will access it.