JS Pass Parameters

Source: Internet
Author: User

Numerical transfer of parameters in/js

This pass is equivalent to copying the value of Count to a num,num change does not affect the count (two different memory regions)

function addten(num) {

num + = ten;

return num;

}

var count = ;

var result = Addten (count);

Console.log (count); //20

Console.log (Result); //30

The transfer of parameters in JS

This pass is the value of person (the person here gets a pointer to an object address in memory, which is remembered as a pointer), so add the name to obj

property is to add the Name property to the corresponding memory area , and the result is that the person takes the name attribute to get

function setName(obj) {

console.log (obj);

obj.name = "Meinv";

}

var person = new Object ();

SetName (person);

Console.log (person.name); //MEINV

In fact, the essence of both methods are the same, are the corresponding values passed the past, the difference is the second pass is the memory address,

All parameters of the function are passed by value, that is, the values outside the function are copied to the parameters inside the function

JS pass-through parameters

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.