let elements = new Array("apple", "banana", "orange");
let elementsRef = elements;
elements.push("grape");
console.debug(elementsRef);
console.debug(elements);
I find it confusing how elements
and elementsRef
are considered the same even after adding "grape" to elements
while referencing elementsRef
. Shouldn't elementsRef
only have ("apple", "banana", "orange")?
If elementsRef
continuously points to elements
, why do we bother with an argument like elements = elementsRef
? I'm still unable to grasp the concept. Can someone explain how this works and why JavaScript allows variables to reference each other indefinitely?