0
pls explain me in easy english what is pass by reference and pass by value in javascript
2 ответов
0
in Javascript only passing by value is supported for primitive values. it means that the function modifies a copy of the passed variable not the original.
for example:
function addTwo(x) {
x = x +2 ;
return x;
}
var y = 10;
var result = addTwo(y);
console.log(y); // 10 -- no change
console.log(result); // 12
see even if we modify the variable "y" in the function it's still 10 not 12.
passing by reference would change the initial value of "y" too.
0
by reference: variable container.
by value: variable content.