Origin of the problem:
1<! DOCTYPE html>234<meta charset= "UTF-8" >5<title>Document</title>67<body>8 9</body>Ten<script type= "Text/javascript" > One varA = []; A - functiontest1 (aa) { - varb = 3; the Aa.push (b); -Console.log (' AA: ' + AA);//[A] - } - + Test1 (a); - +Console.log (a);//[A] A at /************************************/ - varc = 1; - - functiontest2 (cc) { - varD = 3; -CC = CC +D; inConsole.log (' cc: ' + cc);//4 - } to + test2 (c); - theConsole.log (c);//1 * $</script>Panax NotoginsengYou can see that when an incoming parameter is an array, the function is called, the value of the parameter changes, but the value of the parameter is unchanged when the number is passed in.
The cause of the problem is as follows:
The value of the JS function and the parameters of the transmission
Pass value: Just pass the value of the variable into the function, the function will also configure memory to save the parameter value, so it does not change the value of the original variable.
Address: The memory location where the variable is actually saved is passed into the function, so if the value of the parameter is changed in the function, the value of the original parameter is also changed.
Numeric, String, and Boolean-----pass values
objects, arrays, and functions----address
String Object--Address
Original address: http://www.cnblogs.com/Mblog/archive/2009/12/24/1631215.html
Workaround: The function ends with return
About JavaScript functions and their parameters