after reading the book of higher education, the chapter on function transfer, there is such a code:
function setName(obj) {
obj.name = ""
obj = new Object()
obj.name = ""
}
var person = new Object()
setName(person)
console.log(person.name)
The book says that function parameters are passed by value. When obj is rewritten inside the function, this variable refers to a local variable, but I wrote one myself:
var obj1 = new Object()
var obj2 = obj1
obj1.name = ""
obj1 = new Object()
obj1.name = ""
obj2.age = 22
console.log(obj1.age) //undefined
console.log(obj2.name) //
after rewriting obj1, change the value of obj1, and the value of obj2 does not change. On the contrary, after changing the value of obj2, it will not change either. Isn"t this the same as passing parameters to the function? they are all passed by value
.