1. Primitive type value undefined, Null, Boolean, number, and String
Copy process for base type values ( plot )
The base type value occupies a fixed amount of space in memory and is therefore stored in the stack memory;
Copying a base type value from one variable to another creates a copy of the value;
2. Reference type value
Variables in variable objects and objects stored in the heap ( plots )
The value of a reference type is an object that is stored in heap memory;
A variable that contains a reference type value actually contains not the object itself, but a pointer to that object;
Copying the value of a reference type from one variable to another is actually a pointer, so two variables end up pointing to the same object;
3. Pass parameters, pass by value, pass by reference
The parameters of all functions in ECMAScript are passed by value. In other words, copying the values from the outside of the function to the parameters inside the function is the same as copying the value from one variable to another.
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. There are a lot of developers who may be confused at this point,
Because access variables are both by value and by reference, parameters can only be passed by value
function Addten (num) { + =ten ; return num;} var count =; var result =////30
function setName (obj) { = "Nicholas";} var New Object (); SetName (person); alert (person.name) ; // "Nicholas"
function setName (obj) { = "Nicholas"; New Object (); = "Greg";} var New Object (); SetName (person); alert (person.name) ; // "Nicholas"
JavaScript Advanced Programming Notes (Chapter 4th variables, scopes, and memory issues)