js simple data types and complex data types

Simple data types are called elementary data types and value type or, when the stored value is stored in the variable itself,

string,number,boolean,undefined,null; 

Special case: simple data types null value returns a null object Object;

 

Complex data types

Objects created by the new keyword (system objects, custom objects), as Oblect, Array, Date;

Heap and stack

Stack (OS): automatically assigned by the operating system releases the stored function parameters, local variables, and the like, which operate in a manner similar to the data stack structure, simple data types to be stored inside the stack- stack directly in a open space with to store the value of deposit

Stack (OS): storing complex types (objects), the release is generally assigned by the programmer, if the programmer does not release, recovered by the garbage collection mechanism, complex data type which is stored in the stack , the stack inside the first storage address, hexadecimal represents a system, then this address points to the inside of the stack data.

Note: The concept of JavaScript, there are no stack by stack, it can help to better understand the code implementation

Simple data types parameter passing

Parameter function can also be seen as a variable, when we put a value type variable is passed as a parameter to a function parameter, in fact, is to copy a variable to the value of the parameter stack space, then the interior in the method to make parameter changes will not affect the external variables

Fn function (A) { 
                A ++ ; 
                the console.log (A); 
            } 
            var X = 10 ; 
            Fn (X); 
            the console.log (X); 
            // output value 11, 10

Complex data type parameter passing

Parameter function can also be seen as a variable, when we put a reference type variable is passed to a function parameter, in fact, is to copy the variables on the stack space reserved heap address to the parameter, parameter and argument in fact the reservation is the same heap address, so the operation is the same object.

 

Guess you like

Origin www.cnblogs.com/echol/p/12483766.html