js a parameter passing Object, passed by reference

// explain what the code output below? Why? 
var obj = {}; // . 1, where the external variable obj stored address, pointing to the back of the object {}, assume that the target space here called address. 1 
AAA = {Age:. 11 }
 function the setName (obj) { // complex data type 2, where an equivalent var obj, so that the internal function is a local variable obj 
obj.name = 'John Doe'; // 4, where the address stored in internal variable obj is an external transfer case an incoming address, the address of the object name is stored in a 'John Doe' 
obj = {}; // . 5, where the object behind {} is assumed that storage space called address 2, address variable equal to the number stored in the obj 1 address change became 2 
obj.name = 'John Doe'; // 6, the object name is stored in the address 2 'John Doe' 
} 
the setName (obj); // . 3, where the external address of a transfer obj came 
console.log (obj.name); // 7, console.log () is an external print obj argument, it points to has not changed, 
// It has been stored in the address 1, the print out is the address name 1, in order to 'John Doe'

 

Guess you like

Origin www.cnblogs.com/yummylucky/p/10386133.html