JavaScript variable assignment and parameter passing

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.