Js Variable Reference Quickie
Posted
by
Nikki
on Stack Overflow
See other posts from Stack Overflow
or by Nikki
Published on 2012-03-31T11:18:41Z
Indexed on
2012/03/31
11:29 UTC
Read the original article
Hit count: 227
JavaScript
Hoping someone can clear this up for me.
Let's say I have 2 globals: var myarray=[1,3,5,7,9],hold;
and then I do this:
function setup()
{
alert (myarray[0]);//shows 1
hold=myarray;
alert (hold);//appears to show 'hold' containing all the values of myarray. first number shown is 1
myarray[0]=2;
alert (hold);//shows the values of myarray with the updated first entry. first numbe shown is 2
}
Am I to take it that 'hold' is simply keeping a reference to myarray, rather than actually taking all the values of?
© Stack Overflow or respective owner