1. Function parameters: passing by value
For numbers, strings, and so on, their values are passed to the function arguments, and the changes to the function parameters do not affect the variables outside the function.
For arrays and objects, etc., the value of the variable of the object (array) is passed to the function parameter, which holds the address to the object (array). When a function changes the contents of an object (array) that the address points to (such as an assignment), it also changes the contents of the object (array) to which the function's external variables are directed, and when the function changes the address of the variable (for example, assignment), it loses contact with the variable outside the function and becomes a completely different object. Does not cause changes to external objects of the function. When a function operates on a variable, it does not lose contact and still operates on the same object
2. Function scope and declaration in advance
var a =1; function Test () { alert (a); var a =2; alert (a); } Test (); // output undefine and 2 // all variables declared within the function scope of JavaScript are visible inside the function body // The local variable of the function obscures the global variable of the same name, but it is only copied when the local variable is executed, and is undefined when it is not executed .
Javascript--study