An in-depth article on just this subject can be found at SessionStack. Be warned, it’s the DEEP end of the pool.
That said, there is a difference between strings and objects. When I pass them into a function, they are handled very differently: a string is passed in by value, which means the value itself is passed, and not the memory place in which that original variable was stored. In the case of an object (or an array), we don’t pass that to a function by value, we pass it by reference. This means that we are sending our function that memory location and saying “Go ahead and muck with the original copy!”
There are ways around that, as you’ll see when you get to that point, but I think that may be what you are seeing - when passed into a function, primitives (like Numbers or Strings or Booleans) are passed by value, while Objects or Arrays are passed by reference.