Primitives are immutable, there is no way to change its value.
var a = 'abc';
a[0] = 'b';
console.log(a);// abc as it is immutable
However, if I use wrapper object
var a = new String('abc');
typeof a// object
a[0] = 'b';
console.log(a);// abc <----- I actually expect it to be bbc as a is a object which by default should be mutable.
Can someone explain this to me? Is it my misunderstanding of the concept of "mutable" and "immutable" that makes myself confused?
new String()creates a String object. You can't reference or modify the internal string value, you can only read it (e.g. using valueOf). This allows primitives to be treated like objects for convenience when calling methods, but it doesn't allow for assigning values (which, if possible, would make life extremely confusing).