The original intention of this series of articles is to “let each front-end engineer master the high frequency knowledge, for the work of power”. This is the front end of the third cut, I hope friends pay attention to the public number “kite”, armed with knowledge of their minds
3.1 Basic Types
The basic data types in JS include: Number, String, Boolean, Null, Undefined, Symbol (introduced in ES6, indicating unique), which has the following characteristics:
- Basic types of access are by value;
- Cannot add properties and methods;
- There is a stack area for variables of basic types, including the variable identifier and the value of the variable. (The stack area is not set too large, mainly for the existence of basic types);
- The basic type of replication is the creation of a new storage area in stack memory to store new variables;
- Comparisons of primitive types are value comparisons.
3.2 Reference Types
Js contains three types of reference types:
- Basic reference types: Object, Array, RegExp, Date, Function;
- Basic wrapper types: String, Number, Boolean;
- Single built-in objects: Global, Math.
It has the following characteristics:
- Values of reference types are accessed by reference;
- Reference types can have properties and methods that can change dynamically;
- Store the stack and heap areas that require memory, where the stack area holds variable identifiers and Pointers to the object in memory;
- A comparison of reference types is a comparison of references;
- A copy of a reference type copies the reference address.
3.3 Scaling – Why do we need “stack” and “heap” storage
Because the JavaScript engine needs to use the stack to maintain the state of the context (call stack) during the execution of the program, if the stack space is too large (that is, all the data is stored in the stack space), the context switching efficiency will be affected, and thus the execution efficiency of the whole program will be affected. Therefore, the stack space is usually not set too large. Used to store small data such as basic types, while reference types are stored in the heap.
1. If you think this article is good, share and like it so that more people can see it
2. Pay attention to the public number of kite, and the number of the Lord together to kill the front hundred.