last day (15 days later) » 

7:39 PM
Hello there. Thank you for your help.
 
hi
what is your problem with the array?
 
I'm new to JavaScript. Following a book, and it was a practice question, trying to solve it.
My problem is that I don't really understand object reference.
Let me ask you this:
Let's say we have this function:
function word(hey) {}
 
and we have this array:

let myArray = [1, 2, 3];
when it is called:
word(myArray);
Does it in fact bind as follows:

let hey = myArray;
 
thats right.
 
7:46 PM
But then how is it ever possible to modify myArray itself?
How can you ever jump from local to global scope?
 
you could use array/object function which works with that object, like push for arrays.
it changes the array, but do not create a new one.
 
Yeah, I see that. But any manipulation will be over the variable hey
and changing hey wouldn't change anything for myArray, would it?
 
actually you have two variables who are pointing to the same array. if you change something with hey, the result is reflected in myArray.
 
but then why isn't it the case with this statement:

array = reverseArray(array);
because it is in fact like this:
let array = ab;
array = reverseArray(array);
so ab should change too?
 
no. ab has still the same object reference to the original array and array has a new object reference.
 
7:55 PM
I don't get it why.
Why does it work in the case of pop() and not assignment such as array = reverseArray(array);?
 
Array#pop does not change the reference, but works with the array. it mutates the array.
 
I suppose I need to read about object reference in JavaScript.
 
yes, please.
 
thank you for your help
 
you are welcome.
 

last day (15 days later) »