I need some help understand why a relationship is created between arrays when I replicate an array by reference. Take the following example:
let a = [1,2,3];
let b = a;
b.push(4);
console.log(b); // [1,2,3,4]
console.log(a); // [1,2,3,4]
a === b; // true
For some reason, {a} changes when I modify {b}, when I expected them to be independant arrays.
This kind of relationship is not true for variables, it appears. Take the following example:
let a = 'test';
let b = a;
b = 'test1';
console.log(b); // "test1"
console.log(a); // "test"
a === b; // false
Does anyone know the reasoning behind the behavior for arrays?