The ECMAScript variable may contain values for two different data types: the base type value and the reference type value.
Created in a similar way: Create a variable and assign it a value.
(1) Comparison of base type values and reference type values
base type value |
reference type value |
|
|
Undefined, Null, Boolean, number, and String |
|
stack memory |
saved in in |
|
|
|
|
|
|
|
|
(2) Copy variable value
I. Procedure for copying a type value:
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 assigned to the new variable.
II. Procedures for copying reference type values:
When a value of a reference type is copied from one variable to another, the value stored in the variable object is also copied 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.
(3) Parameter transfer
The parameters of all functions in ECMAScript are passed by value . That is, the delivery of a primitive type value is like a copy of a primitive type variable, whereas a reference to a value of a type is the same as a copy of a reference type variable.
(4) Detection type
detecting basic data Types: The typeof operator is the best tool for determining whether a variable is a string, a numeric value, a Boolean, or a undefined.
detecting the type of value/object of a reference type: The instanceof operator always returns True when the instanceof operator detects a reference type value and an Object constructor, and the operator always returns false if the value of the base type is detected using the instanceof operator. Because the base type is not an object. *ECMA-262 specifies that any object that implements the [call] method internally should return "function" when the typeof operation is applied. Applying typeof to regular expressions in different browsers returns different values, function or object.
JS elevation basic type and value of reference type learning notes