15.2.11 Copying reference type variables Things are different when one is working with variables of reference types. Consider the following code, where first an array called myArray is created with some initial values, next a variable called thing2 is assigned the value of myArray: var myArray = new Array 6, 3, 5, 1 ); var thing = myArray; Since myArray is a reference to the array values in memory, what has been copied into thing2 is the reference — so now both myArray and thing2 are referring to the same set of values in memory The implications are that if a change is made to the array values, since both myArray and thing are referring to the same values in memory, both will be referring to the changed array. Exercise 2
10 What is the value of myArray[2] after the following statements have been executed var myArray = new Array 6, 3, 5, 1 ); var thing = myArray; thing = 27; thing = 19; thing = 77;