This post consists of: http://xinpure.com/javascript-value-types-and-reference-types/
JavaScript variable type
Value types: String, Number, Boolean, Null, Undefined
Reference types: Arrays, objects, functions
Comparison of value types and reference types
Compare these two types with two instances (Debug environment: Chrome Developer Tools Console)
Value type instance
var a = ‘hello‘;var b = a;b; /* hello */a = ‘world‘;b; /* hello */
The value type of the variable assignment process, is actually allocated a new memory space, the same value but the two do not interfere
Reference type instance
/* 对象或数组 */var a = {"x": 0};var b = a;b.x; /* 0 */a.x = 1;b.x; /* 1 */a = {"x": 2}; /* 此时,a 指向了另一块内存空间,b 的值将不受干扰 */b.x; /* 1 */a.x = 3;b.x; /* 1 *//* 函数 */var a = new Function("alert(‘test‘)");var b = a;b(); /* 执行 alert(‘test‘) */
The variable assignment procedure for a reference type refers to two variables pointing to the same piece of memory space, where a change in the value of one variable causes a change in the value of the other variable
Javascript value types and reference types