Pass-by-value (byvalue): When you assign a value between two variables or pass a variable as an argument to a function, the value in the original variable is assigned to the other party (the new variable).
Value for Primitive type: Modify new variable without affecting the original variable
object to reference type: Modifying an object with a new variable is equivalent to modifying the original object directly.
First example: Values of the original type
1 var a=10; 2 var b=a; // Take out the value in a and copy one to B. 3 a++; 4 Console.log (a); // One 5 Console.log (b); // Ten
Second example: Objects of a reference type
1. Functions
1 var card=10; 2 function Buy (Card) {3 card-=3; 4 Console.log (card); 5 }6 Buy (card); 77 console.log (card); Ten
2. Arrays
1 varmy=["Package", "Package", "Package", "Package", "package"];2 //0 1 2) 3 43 varIpxmy;4Lp[0]= "";5Console.log (String (my));//46My[4]= "";7Console.log (String (LP));//38 9 vararr=[1,2,3,4,5];Ten //0 1 2) 3 4 One functionFun (arr) { AArr[5]=6; -arr=[1,2,3]; -Arr[6]=12; the Console.log (arr); - } -Fun (arr);//123,,, -Console.log (arr);//123456
javascript--functions-Passing by value