In JavaScript Advanced Programming, page 3, 4.1.3, we talk about passing parameters:

Arguments to all functions in ECMAScript are passed by value

Pass by value

var value = 1;
function foo(v) {
    v = 2;
    console.log(v); //2
}
foo(value);
console.log(value) // 1
Copy the code

reference

var obj = {
    value: 1
};
function foo(o) {
    o.value = 2;
    console.log(o.value); //2
}
foo(obj);
console.log(obj.value) // 2
Copy the code

Share transfer

Passing by reference is passing a reference to an object, and passing by share is passing a copy of a reference to an object!

var obj = {
    value: 1
};
function foo(o) {
    o = 2;
    console.log(o); //2
}
foo(obj);
console.log(obj.value) // 1
Copy the code

So if you change O. value, you can find the original value by reference, but if you change O directly, you won’t change the original value. So the second and third examples are actually shared.

Finally, you can understand it this way:

Parameters are passed by value if they are of basic type and shared if they are of reference type.

But because a copy copy is also a copy of a value, it is also considered passed by value in elevation.