老师,为什么会出现下面两种情况,对象里面的 对象的属性值修改后会影响前面的输出?
对象里面的对象,在栈和堆上具体是怎么储存的呢?
let obj = {
name: 'LiMing',
age: '30',
skill: {
name: 'code'
}
};
console.log(obj);
// {name: "LiMing", age: "30", skill: {…}}
obj.age = '31';
console.log(obj);
// {name: "LiMing", age: "31", skill: {…}}
let obj = {
name: 'LiMing',
age: '30',
skill: {
name: 'code',
year: 1
}
};
console.log(obj);
//{name: "LiMing", age: "30", skill: {name: "code", year: 2}}
obj.skill.year = 2;
console.log(obj);
//{name: "LiMing", age: "30", skill: {name: "code", year: 2}}
登录后可查看更多问答,登录/注册
前端无门槛学习,从ES6到ES11,一套课程掌握JS最新语法
了解课程