Language type
- Static languages: The variable data type needs to be confirmed before use (c)
- Dynamic languages: Data types need to be checked during runtime (JS)
- Strongly typed languages: Implicit type conversions are not supported
- Weakly typed languages: support implicit type conversions (C, JS)
Js: You can use the same variable to store different types of data without having to define the data type of the variable in advance
Js data types: only obj is a reference type, all others are primitive types
-
null
-
undefined
-
number
-
object
-
string
-
boolean
-
Symbol: symbol type
-
Bigint: indicates the new number type
Function demo() {var a = “mine” var b = a “mine” var c = {name: “community “} var d = c} // The original type is stored in the stack (small space), the reference type is stored in the heap (large space)
The stack and heap
Why heap and stack data structures?
Stack to maintain the context state during program execution, all data put in the stack, will affect the context switch efficiency, and then affect the execution efficiency of the whole program
// Closure is an object that exists in the heap, Function demo() {var myName = "test1" const test2 = 2 var innerFun = {getName:function(){ console.log(test1) return myName }, SetName :function(newName){myName = newName}} return innerFun} var test = demo() test.setName(" ") test.getName() console.log(test.getName())Copy the code
Garbage Collection strategy
- Manual recovery: c
free()
- Automatic collection: JS, Java, Python -> garbage collector frees memory
Stack recovery:
ESP: indicates a pointer to the current execution status
After the function completes, ESP moves down to the next execution context, which is stack destruction
Pile of recycling
Old area: mark – clear, mark – finish
Is recycling causing congestion?
Js runs on the main thread. Once garbage collection is performed, js currently being executed needs to be suspended, affecting application performance and response performance. In order to avoid lag, incremental marking algorithm is implemented