I would not expect foo to change at all in this example, but when I modify it as an array in the function, it changes the argument. Notice foo is not changed by function1...I guess because it doesn't modify the argument directly??? Any help avoiding this would be greatly appreciated.
var foo = [1,2,3];
bar = function1(foo);
bar = function2(foo);
bar = function3(foo);
function function1(newFoo){
newFoo = [newFoo,'a',1];
return newFoo;
} //foo after function1 = 1,2,3
function function2(newFoo){
newFoo[0] = 'a';
return newFoo;
} //foo after function2 = a,2,3
function function3(newFoo){
newFoo.push('4');
return newFoo;
} //foo after function3 = a,2,3,4