This has always been a bit confusing to me and my programming jargon isn’t adequate to google it. Not even sure if the title makes sense.
For example, if I have an array of objects like so…
var someObjects = [{type: 'apple'}, {type: 'orange'}, {type: 'banana'}];
…and I say that…
var theBestFruit = someObjects[2];
but then we add another object to the beginning, shifting all the elements…
someObjects.unshift({type: 'pear'});
Will theBestFruit still reference the banana object? Or will it now be the orange? Some explanation would be much appreciated.
theBestFruit = someObjects[2]will look up what is at the second (or third, if you count as a non-programmer :p ) position ofsomeObject, (which is the object{type: 'banana'}, and assign a direct reference to this object totheBestFruit. The reference is not to the second object ofsomeObjects. Thus, ifsomeObjectschange,theBestFruitwill still be{type: 'banana'}.The best way to test it would be to… test it.