值类型和引用类型
let num1 = 100
let num2 = num1 //num2的值由num1传入
console.log(`num1=${num1},num2=${num2}`);
num2 = 200 //num2的值重新修改后,num1不受影响
console.log(`num1=${num1},num2=${num2}`);
console.log('--------------------------------');
// 引用类型:数组,对象
let obj1 = {
name:'张杰',
age:20,
sex:'男'
}
// 将obj1传给obj2,其实传的是obj1的地址
let obj2 = obj1
console.log('obj1',obj1);
console.log('obj2',obj2);
console.log('========================');
// 修改obj2的属性值,obj1也会发生变化,因为obj1和obj2的地址是一样的
obj2.name='谢娜'
obj2.age=25
obj2.sex= '女'
console.log('obj1',obj1);
console.log('obj2',obj2);
console.log('----------------------------------');
obj2 = {
name:'周杰伦',
age:35,
sex:'男'
}
console.log('obj1',obj1);
console.log('obj2',obj2);