DEV Community


Discussion on: JS Concepts: Value vs. Reference

aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan

When we assign non-primitive value to the variable, we copy them by reference. In other words, variables are given a reference to that value, so they don’t actually contain the value.

This actually isn't true. The assignment operator assigns a value in all cases (for both objects and primitives). In the case of objects, the "value" is a memory address (a pointer). Learn more on that here in an article I wrote: Is JavaScript Pass by Reference?. This is how Chrome's v8 engine works, for example—the "references" are really just pointers under the hood.