Take a look at this snippet of JavaScript code:
var x = [1, 2, 3],
y = x;
y[1] = 3;
x; // x === [1, 3, 3] Why does this happen?
Why is the value of "x" changing when I update "y[1]"? I tried it in both Firefox and Chrome and got the same result. This doesn't happen with a simple number. Is this the expected behavior?
var foo = 1,
bar = foo;
bar = 3;
foo; // foo === 1 Great!