Js array assignment problem: value passing or reference?

topic description

var a = [1,2,3];
var b = a;
a = [4,5,6];
alert(b);  //[1,2,3]


var a = [1,2,3];
var b = a;
a.pop();
alert(b);  //[1,2]
// 

topic source

Zhihu

< hr >

a = [4,5,6];//a
a.pop();//a
b = a;//bbaa
//ab

but I don"t think it makes sense. I think it should be this execution order, but from the result, I am wrong ~

a = [4,5,6];//a
b = a; // 
a.pop();

after reading their answers in Zhihu this morning, can you give me a brief and concise answer?
I would like to give you some advice on my order.

Mar.28,2021

is a building,
is also a building, and
an and b are two pieces of tin with house numbers.

var a = [1,2,3];  //a 123
var b = a;        //b a123
a = [4,5,6];      //a456
alert(b);  //[1,2,3]  //b123b123


var a = [1,2,3];    //a 123
var b = a;          //b a123
a.pop();            //a,a1233
alert(b);  //[1,2]  //b 12312

</span>

var a = {id: 1};
var b = a;
a = {id: 2};
console.log(b); // _> {id: 1};
Menu