first , the variables in JavaScript are divided into basic types and reference types.
A basic type is a simple piece of data that is stored in the stack memory, whereas a reference type refers to an object that is stored in the heap memory.
1. Parameter passing
The passing of all parameters in JavaScript is a value pass.
1.1 Delivery of basic data types (undefined, null,boolean,number,string)
1--->var money = 10;
2--->var t=function (money) {
Money = 5;
alert (money); 5
}
3--->t (money);
4--->alert (money); 10
The execution process ① the value of the initialization money in the global environment is 10; ② creates the execution environment of the function T, ③ executes the T function to copy the value of the variable of money in the global environment to the money function in the T function, the money in the body is changed to 5 and then executed ④ The money value in the global is still 10
1.2 Passing of the object (pass is the reference address of the object)
1--->var person = new Object ();
2--->
4--->alert (person.name); Zhangsan
The execution process ① the person in the global environment, the person refers to an empty object on the stack, and ② copies the object address value referenced by the person to student; ③ adds the student referenced object to the name attribute to Zhangsan④ Because student and person refer to the same object, the value is zhangsan!
Example diagram
JavaScript Elevation notes-------Fourth chapter variables, scope, and memory issues