About basic types and reference types of personal understanding

        1. Basic Types

                A. There are five basic types, Number, String, Boolean, Null, Undefined

                B. The concept underlying type does not stack, heap only for reference types.

                    All basic types are in the form of key-value stored in the stack, wherein the value of the base type immutable, unless it is re-assignment,

        such as:

var A = " 1234 " ; 
A [ 0 ] = " K " ; // value itself modified, invalid 
the console.log (A) // 1234 

A = " K " ; // reassign 
the console.log (A) / / k

        2. The reference type

               Reference types, such as Array, Object, Function, Date, RegExp, etc.

                     All types are references to the form of key-value stored in the stack, wherein, the value stored key-value is a reference type pointer address, where the address points to a stack space, this storage space with the value of the data reference type.

                    note:

                The reference data is "stack value", the value set stack VALUE1  , Key-value in the form of the inside of the stack is the value of the target value value, this stack is set " value2 " In the present example, VALUE1 is changeable, value2 are immutable, unless it is re-assignment.

         such as:

 // stack value, i.e. value1, may be varied 
var A = { " name " : " Jack " }; 
A = []; // reassign 
the console.log (A) // [] 
 
// stack value, i.e., value2, the basic data types as immutable 
var A = { " name " : " Jack " }; 
a.name [ 0 ] = " 0 " ; 
the console.log (A) // { "name": "Jack"}

        3. The value of the pass-by-pass

                As shown below:

                3.1 A code block is the mass value

                    A block of code, a and b will open up a space used to store the value in the stack area 10, and stored in the form of key-value. A code block is the mass value

                3.2 B is the pass-code block

                    B block of code, a1 will open up a space for storing the address pointer, then a pointer will be assigned to the address a1, b1, i.e. b1 will also open up a space to put the pointer address, and a1, b1 stack pointer is pointing to the address "heap value" areas, namely value1 .

 

        4. Compare

               4.1 basis for comparison is the type of comparison values

such as:

var a = 1;
var b = 1;
console.log(a == b);//true

 

                Compare 4.2 is more of a reference

        With a quote comparison is equal, unequal comparison of different references.

        such as:

// different comparison reference 
var P1 = {};
 var P2 = {}; 
the console.log (P1 == P2) // to false 
 
// different comparison reference 
var P3 = { " name " : {}, " Age " : 30 };
 var P4 = { " name " : {}, " Age " : 30 }; 
the console.log (p3.name == p4.name); // to false (this is a reference to compare) 
the console.log (P3 == p4.age .age); // to true (this is the comparison value) 
 
// comparison with reference
was P5 = {};
was P6 = P5; 
console.log (P5 == P6) // threaten

               If the reference is assigned another type, then the current reference pointer address will be cut off and values.

            As shown below:

 

 

When the re-assignment of a1, a1, and "heap value -> {}" is replaced by a link to a new pointer address, i.e., "the value of the stack -> []" 

 

Guess you like

Origin www.cnblogs.com/Chansea/p/11772874.html