By Reference And By Value

Objects are passed by reference! Not value

function changeObj(foo) {
 
  foo.prop1 = 1;
  foo.prop2 = 2;
 
}
 
var obj = {};
obj.prop1 = function(){};
obj.prop2 = 1;
 
changeObj(obj);
console.log(obj); 
 
/* 
Output
 
Object {
  prop1: 1,
  prop2: 2
} 
*/
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License