Come to the conclusion first!
Variable assignment:
Base type: passed by value (that is, a copy is copied)
Reference type: passed by reference (that is, a reference to the object is passed)
Parameter passing
Base type: passed by value (that is, a copy is copied)
Reference type: Passing by value (that is, copying a copy)//There is a doubt!!!!
If all the above conclusions are known, you can stop looking down ...
Variable assignment- basic type
var num1 = 1;
var num2 = NUM1;
Num2= 2;
alert (NUM1);//1
Variable assignment-- object type varnew object (); // Modify the point var obj2 = obj1; ' haha ' ; alert (obj2.name); // The result is haha .
function SetName (obj) {obj.name='haha'; Obj=NewObject (); Obj.name='Wuwuwu'; } varperson=NewObject (); alert (person.name);//according to the author, here is the haha instead of the Wuwuwu. Description is a value pass rather than a reference (feel the problem with this example)//But the result of my variable assignment is still haha, not wuwu. varObj1 =NewObject (); //Modify the Point varObj2 =obj1; Obj2.name='haha'; Obj2=NewObject (); Obj2.name='Wuwuwu'; alert (obj1.name);
JavaScript variable assignment and parameter passing