Home > Web Front-end > JS Tutorial > What is js stack

What is js stack

一个新手
Release: 2017-09-26 09:43:31
Original
1823 people have browsed it

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;
}
Copy after login


Step 1: Pre-parsing process stage, all variables and functions declared by var Mention the top:

var x,
var y,
function f1(a,b){}
Copy after login

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
返回值
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template