2

I'll start with the code:

var x = {list: [1, 2, 3], num: 4};
console.log(x);
function asd(x) {
    x.list[0] = 4;
    return x;
}

console.log(x);
asd(x);
console.log(x);

At the firefox console, the result was this:

list: Array [ 4, 2, 3 ]
num: 4

list: Array [ 4, 2, 3 ]
num: 4

list: Array [ 4, 2, 3 ]
num: 4

How can that be? Shouldn't it be [1, 2, 3] first, and then [1, 2, 3], and only then [4, 3, 2]? What happened here?

Physicist137
  • 228
  • 2
  • 9

0 Answers0