Heap and stack
- The difference in stack space allocation:
1. Stack: The operating system automatically allocates and releases the parameter values of the stored function, the values of local variables, etc. Simple data types are stored in the stack
2. Heap: Stores complex types (objects), which are generally allocated and released by the programmer. If the programmer does not release, they are reclaimed by the garbage collection mechanism.
-
Storage of simple data types
The data of the value type variable is directly stored in the variable (stack space)
-
Storage of complex data types
Reference type variables (stack space) are stored in the address, the real object instance is stored in the heap space
Common basic data types:
Number, String, Boolean, Undefined, Null, Symbol (new unique values in es6 ) and BigInt (new in es10) ;
The basic data types are accessed by value, because the actual value stored in the variable can be directly manipulated.
Reference type data:
Object。包含Object、Array、 function、Date、RegExp。
The reference data type of javascript is an object stored in the heap memory.