[Javascript] view plaincopyprint?
I. javascript Variables
Javascript variables can be used to save two types of values: basic type values and reference type values.
The basic type value comes from the following five basic data types: Undefined, Null, Boolean, Number, and string. The reference types include object, Array, date, RegExp, function, and basic packaging types (Boolean, Number, and string ).
The basic type value occupies a fixed size in the memory, so it is stored in the stack memory. The reference type value is actually an object and is stored in heap memory.
Therefore, copying a variable that saves the basic type value creates a copy, while copying a variable that saves the reference type value is actually copying a pointer.
You can use the typeof operator to confirm the basic type value, and use the instanceof operator to confirm the reference type.
The basic type value is equivalent to a network node, and the reference type is equivalent to a line between nodes. Because of the existence of these nodes and connections, the program becomes a whole and a system.
Note: variables can be accessed by value or by reference, but function parameters can only be passed by value.
Ii. Reference count
When a variable is declared and a reference type value is assigned to the variable, the number of times this value is referenced is 1. if the same value is assigned with another variable, the value is incremented by 1 ,. For example
[Javascript]
Var element = document. getElementById ("myId ");
VAR oBj = element;
Var element = document. getElementById ("myId ");
VAR oBj = element; is a reference process. The reference count is a method for javascript garbage collection. Removing unnecessary references properly helps improve javascript performance.