值类型与引用类型区别

const obj1 = { x: 100, y: 200 }
// 引用类型赋值,知识把指针指向obj2,与原数据有关系
const obj2 = obj1
// 值类型赋值,相当于拷贝一份,和原来没有关系
let x = obj2.x
x = 101
obj2.x = 102
console.log(obj1)

答:{x: 102, y: 200}

results matching ""

    No results matching ""