Recently i heard about something called shallow copying in javascript.
I learned that array.slice(0) will return a shallow copy of the original array (meaning changes made to the original array will be reflected in the duplicate array)..but it is not happening.
original = [1,2];
duplicate = original.slice(); //thinking it as a shallow copy
original.push(3);
now original array has [1,2,3] but duplicate array has [1,2].
As far as i have understood, i thought shallow copy will reflect the changes in both the arrays, hence both array should be same.
But if i do like this, it is happening:
original = [1,2];
duplicate = original; //thinking it as a deep copy
original.push(3);
Are there any great explainers out there???