Two types:
ECMAScript variables contain two different types of values: basic type value and reference type value;
Basic type value: refers to a simple data segment stored in the stack memory;
Reference type value: refers to those objects stored in heap memory, which means that the variable is actually just a pointer, which points to another location in memory, and the object is saved from that location;
Two ways to access:
Basic type values: accessed by value, operating on the value they actually saved;
Reference type value: accessed by reference. When querying, we need to read the memory address from the stack first, and then follow the clues to find the value stored in the heap memory;
Two types of copying
1. Copying of basic type variables: When copying from a variable to a variable, a new value will be created in the stack and then the value will be copied to the position assigned to the new variable;
2. Copying of reference type variables: The copy is a pointer stored in the stack, copying the pointer into the space allocated for the new variable in the stack, and this pointer copy and the original pointer point to the same object stored in the heap;
After the copy operation is finished, the two variables will actually refer to the same object; therefore changing one of them will affect the other;
The above brief discussion of the basic types and reference types of JS is all the content I have shared with you. I hope you can give you a reference and I hope you can support Wulin.com more.