I've read that arrays and objects are "being passed by reference". But I've encountered behavior, which confuses me.
In this piece of code, everything works as I would expect
let first = [1, 2, 3, 4, 5];
let second = first;
first.push(10);
console.log(first); //[ 1, 2, 3, 4, 5, 10 ]
console.log(second); //[ 1, 2, 3, 4, 5, 10 ]
I have troubles understanding the following one
let third = [1, 2, 3, 4, 5];
let forth = third;
third = [11, 12];
console.log(third); //[ 11, 12 ]
console.log(forth); //[ 1, 2, 3, 4, 5 ]
I would expect both variables to be equal, but it works as I'm operating primitives, not an array.