JavaScript variable type
Value types: String, numeric, Boolean, Null, Undefined
Reference types: Arrays, objects, functions
Comparison of value type and reference type
Compare these two types through two instances (Debug environment: Chrome Developer Tool Console)
Value type instance
var a = ' Hello ';
var B = A;
b /* Hello * *
A = ' world ';
b /* Hello * *
The variable assignment procedure for a value type actually allocates a new memory space with the same value but the two do not interfere with each other
Reference type instance
/* Object or array * *
var a = {"X": 0};
var B = A;
b.x; /* 0 * *
a.x = 1;
b.x; /* 1 * *
A = {"X": 2}; /* At this point, a points to another memory space, B's value will not be disturbed.
b.x; /* 1 * *
a.x = 3;
b.x; /* 1 * *
/* Function * *
var a = new Function ("Alert (' Test ')");
var B = A;
b (); /* Execute alert (' Test ') * *
The variable assignment procedure for a reference type is to point two variables to the same memory space, where a change in the value of one variable can cause another variable value to change