1base Type value
Description: Simple data segment:undefined,null,number,string, boolean.
2Reference type value
Description: An in-memory object exists.
3Copy variable values
If you copy the value of the base type from one variable to another, a new value is created on the variable object and the value is copied to the location where the new variable is assigned.
Example:
var num1=1;var num2=num1;
Both the NUM1 and num2 values are 1andare independent, changing the num1 will not change num2 the value.
Note: These two variables can participate in any operation without affecting each other.
When a variable copies the value of a reference type to another variable, it also copies the value stored in the variable object into the space allocated for the new variable. The difference is that a copy of this value is actually a pointer to an object stored in the heap. When the copy operation is finished, two variables will actually refer to the same object.
Example:
var obj1={ name:' 123 '}; var obj2=obj1;obj1.name= ' 345 '; obj2.age=3; Console.log (obj2.name); Console.log ( Obj1.age); /*
345 3
*/
Note: These two variables, changing one of the variables, will affect the other variable.
4Detection Type
Typeof:typeof is a powerful helper for detecting basic data types:
Example:
var a=3; Console.log (typeof a); // Number
However,Typeod is not very useful when detecting objects of reference types, because we do not usually want to know that a value is an object, but rather to know what type of object it is, this time instanceof It's very useful.
Example:
var a=[1,2instanceof Array); // true
The JavaScript variable