SUMMARY
Two types of values can be stored in JavaScript variables: primitive values and reference values. Primitive values have one of the six primitive data types: Undefined, Null, Boolean, Number, String, and Symbol. Primitive and reference values have the following characteristics:
- Primitive values are of a fixed size and so are stored in memory on the stack.
- Copying primitive values from one variable to another creates a second copy of the value.
- Reference values are objects and are stored in memory on the heap.
- A variable containing a reference value actually contains just a pointer to the object, not the object itself.
- Copying a reference value to another variable copies just the pointer, so both variables end up referencing the same object.
- The
typeof
operator determines a value's primitive type, whereas theinstanceof
operator is used to determine the reference type of a value.
All variables, primitive and reference, exist within an execution context (also called a scope...