Stand in line - why is testArr array modified?

Can someone explain how the function knows which array to modify? the global variable “testArr” is not called in this challenge.
why does pushing one of the arguments modify the testArr array?

An easy thing to miss in JavaScript is the difference in how primitive types (string, number, boolean, etc.) and compound types (objects, arrays, etc.) are stored. With a primitive type, it is the actual value that is stored in the memory location, and with a compound type, it is the address pointing to where the data is stored. Most compound types would be much too big to store in one memory slot.

Now, when you send a variable of type number to a function, a copy is made and that is sent. When you send a compound type, the exact same thing is happening, but you are sending the address. So, you have a copy inside the function, but it is pointing to the same location of memory - two variables pointing to the same memory. Any change made to the memory pointed to by one will be seen by the other because they are pointing to the same place.

Does that make sense. A lot of beginning JavaScript learners get tripped up on this. I have the advantage of having learned C first, where you must understand this or you can’t function. But JS kind of simplifies it - and because of that it isn’t often stressed what is really happening.

This is going to come up later when dealing with copying compound types. When you copy an array, you can’t just set one equal to the other like you would with a string. If you did that to an array, you would just end up with two variables pointing to the same array.

Yes, it’s confusing. But you’ll get the hang of it. Just keep at it. Let us know if that isn’t clear.