As i heard, String is immutable in JavaScript then how splice method changing the original String?
As I know
var name = 'Alto';
// it will create an new object in global space memory with 'alto' and assign to name reference.
name = 'swift';
// it will create an new object in global space memory and with 'swift' assign to name reference. ('Alto' string object will be moved to garbage collector whenever possible).
var newName = name.slice(0,2);
// here splicing the 'sw' from 'swift' create an new Object in global space and assign to newName. name will have 'swift' since string is immutable.
var newName1 = name.splice(0,2);
// here cut the 'sw' from 'swift'(original string) and assign to newName. now name will have 'ift'. so how String is an immutable?
Can anyone explain the process behind splice?