I have a little confusion as to how arrays are handled when passed to functions. My question is why does the ouput of sample2.js NOT be null ?
// sample1.js======================================
// This clearly demonstrates that the array was passed by reference
function foo(o) {
o[1] = 100;
}
var myArray = [1,2,3];
console.log(myArray); // o/p : [1,2,3]
foo(myArray);
console.log(myArray); // o/p : [1,100,3]
//sample2.js =====================================
// upon return from bar, myArray2 is not set to null.. why so
function bar(o) {
o = null;
}
var myArray2 = [1,2,3];
console.log(myArray2); // o/p : [1,2,3]
bar(myArray2);
console.log(myArray2); // o/p : [1,100,3]