A total of six types of data in JS:
Five types of value: Boolea number String Null undefined
Reference type: Object----Three major reference types: Object Array Function
Topic 1:var A = 100;
var B = A;
A = 200;
Console.log (b);
Topic 2:var A = {age:20};
var B = A;
B.age = 21;
Console.log (A.age);
The answer to Topic 1 is 100, the answer to question 2 is 21,
Topic 1 is a simple value type that, when you assign a base type from one variable to another, creates a new value on the variable and then copies the value to the location assigned to the new variable.
At this point, the value saved in a is 100, and when a is used to initialize B, the value saved in B is also 100, but 100 in B is completely separate from a, which is just a copy of the value in a, after which,
These two variables can participate in any operation and are unaffected by each other. That is, after the assignment operation, the base type has two variables that are not affected by one another.
Topic 2 is a reference type, and when a value of a reference type is assigned to another variable from one variable, the value of the object stored in the variable is also copied into the space allocated for the new variable.
At this point in the variable is the address of the object in the heap memory, so, unlike the simple assignment, the copy of this value is actually a pointer, and this pointer points to an object stored in the heap memory. Then after the assignment operation,
Two variables all hold the same object address, the two variables point to the same object. Therefore, changing any one of these variables will affect each other.
Therefore, the assignment of a reference type is actually an assignment of the object's value in the stack address pointer, so that two variables point to the same object, and any operation will affect each other.
Computational problems in JavaScript