Home >Web Front-end >JS Tutorial >What is js stack
Stack concept
There is no stack concept in Js. It is introduced for easier understanding and better learning:
Data type
Basic type data is called value type, and complex type is also called reference type
a. Value type, simple data type, when stored, What is stored in a variable is the value itself, so it is called a value type.
b. Reference type, complex data type. When storing, the variable stores only the address and uses it for reference, so it is called a reference data type.
Stack heap space allocation concept
1. The stack
is automatically allocated and released by the operating system to store the parameter values of the function , the value of local variables, etc., the operation method is similar to the stack in the data structure.
2. Heap
stores complex types (objects), which are generally allocated and released by programmers, and can also be recycled by the garbage collection mechanism. The allocation method is similar to a linked list.
varx =5; vary =6; f1(x,y); functionf1(a,b) { a=a+1; b=b+1; console.log("a="+a);//a=6; console.log("b="+b);//b=7; }
Step 1: Pre-parsing process stage, all variables and functions declared by var Mention the top:
var x, var y, function f1(a,b){}
Step 2: Execution phase:
x = 5; y = 6; f1(5,6)调用函数,执行函数体代码; 函数里面var a = 5; var b = 6; a = a+1;//6 b = b+1;//7 返回值
Similarly: complex type data objects are stored in the same way on the stack
The above is the detailed content of What is js stack. For more information, please follow other related articles on the PHP Chinese website!