猿问

如何理解下面一段js代码?

vara={"x":1};
varb=a;
console.log(b.x);
a.x=2;
console.log(b.x);
a={"x":3};
console.log(b.x);
a.x=4;
console.log(b.x);
为什么输出的是
1
2
2
2
Cats萌萌
浏览 409回答 2
2回答

慕桂英4014372

vara={"x":1};//a:object#1{"x":1}varb=a;//b:object#1{"x":1}console.log(b.x);//1a.x=2;//a,b:object#1{"x":2}console.log(b.x);//2a={"x":3};//a:object#2{"x":3}console.log(b.x);//2a.x=4;//a:object#2{"x":4}console.log(b.x);//2
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答