I read a book called \"Professional Javascript for web developer\" and it says: \"Variable is assigned by Reference value or Primitive Value. Reference values are objects st
In javascript the Primitive values
are data that are stored on the stack
.
Primitive value
is stored directly in the location that the variable accesses.
And the Reference values
are objects that are stored in the heap
.
Reference value stored in the variable location is a pointer to a location in memory where the object is stored.
JavaScript supports five primitive data types: number, string, Boolean, undefined, and null
.
These types are referred to as primitive types because they are the basic building blocks from which more complex types can be built.
Of the five, only number, string, and Boolean
are real data types in the sense of actually storing data.
Undefined and null
are types that arise under special circumstances. The 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.
And the Reference types can be of any length -- they do not have a fixed size.