I wonder if this code always works as intended:
var a = [0, 1];
var b = a;
b.push(2);
// a is now [0, 1, 2]
Can in theory methods like ‘push’ or ‘splice’ change the reference of variable (say, if there is not enough memory in previous object location)? In other words, can it be that a != b in my example?
No, methods that you call on an object can’t change the reference of the object.
For a method to be able to change the reference, you would have to send the variable that you are using to reference the object into the method. Without that the method only knows about the object, it doesn’t know about your variable that you use to store the reference, so if it changed the reference to the object your variable would no longer point to it.