Primitive Types and Reference Types
Primitive Types and Reference Types
Numbers, boolean values, and the null and undefined types are primitive. Objects, arrays, and
functions are reference types.
Primitive Types
A primitive type has a fixed size in memory.
For example, a number occupies eight bytes of memory, and a boolean value can be
represented with only one bit.
The number type is the largest of the primitive types.
If each JavaScript variable reserves eight bytes of memory, the variable can directly
hold any primitive value.
Reference types
Reference types are another matter, however. Objects, for example, can be of any
length -- they do not have a fixed size.
The same is true of arrays: an array can have any number of elements.
Similarly, a function can contain any amount of JavaScript code.
Since these types do not have a fixed size, their values cannot be stored directly in the
eight bytes of memory associated with each variable.
Instead, the variable stores a reference to the value. Typically, this reference is some
form of pointer or memory address.
It is not the data value itself, but it tells the variable where to look to find the value.