I don't understand why in the function change2, the console doesn't output 2, but undefined?
var users = {a:1, b:2};
function change1(people){
people.c = {};
var C = people.c;
setTimeout(function(){
C.number = 2;
}, 1000);
}
function change2(people){
people.c = {};
var C = people.c;
setTimeout(function(){
console.log(C.number);
}, 2000);
}
change1(users);
change2(users); // undefined, why not 2?
However, if I replace C.number by people.c.number within setTimeout of change1, it works(outputs 2), why? Don't they refer the same thing?