Reference values are objects stored in memory.When you manipulate an object, you’re really working on a reference to that object rather than the actual object itself. For this reason, such values are said to be accessed by reference.
Dynamic Setting Properties
Primitive and reference values are defined similarly: assign a value to a variable.When you work with reference values, you can add, change, or delete properties and methods at any time. But primitive values can’t added have any properties.
When a primitive value is assigned from one variable to another, the value stored on the variable object is created and copied into the location for the new variable. They have the same value, but completely separate from each other, so they can be used separately with no side effects.
When a reference value is assigned from one variable to another, the value stored on the variable object is also copied into the location for the new variable. The difference is that this value is actually a pointer to an object stored on the heap. Once the operation is complete, two variables point to exactly the same object, so changes to one will reflect the other.
When a object is overwritten inside the function, it becomes a pointer to a local object. That local object is destroyed as soon as the function finishes executing. So
How to distinguish primitive and reference values by type ? When you using typeof operator, typeof null will return "Object" and typeof object also return "Object". In this case, wo should use instanceof operator to help us.
All reference values are instances of Object, but primitives not.