In this block of code the result will be "unll" for the first console and an empty array for the second console
function fn(o) {
o = null;
console.log(o); //console o
}
var x = [];
fn(x);
console.log(x); //console x
but in this block of code
function fn(o) {
o[0] = null;
console.log(o); //console o
}
var x = [];
fn(x);
console.log(x); //console x
when i access the first element of the array the result of both consoles is an array with null value in the first element.
And this is really confusing for me, i understand that in the first block of code the array was passed by value, so it didn't affect the x array.
but why in the second block it was passed with reference!!
So does anyone has an explanation please?