The original address

Everything can be an object in JavaScript, like arrays and functions. An object is a collection of key/value pairs, and the value can be any, which means it can be a primary type or other object. Objects have properties and methods (functions are on top of the object and these properties and methods live in memory by reference) that you can access.

All major types of variables interact by value

First, we declare two variables, A and b. And then we set b equal to a, which is equal to 4. And then we set a to be equal to 2. Now, b is still equal to 4 factorial. This happens because B has its own space in memory!


When setting them equal or passing them into a method, all non-primary type values interact by reference.

In memory they look like:

The variables C and D have the same value and point to the same memory address.

The variable c holds a reference to an array (object). We then assign d the same reference as C. If you then change the value of D by pushing an element into the array, the properties of all the other variables will be changed. They point to the same reference, not a copy.