pls explain me in easy english what is pass by reference and pass by value in javascript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

pls explain me in easy english what is pass by reference and pass by value in javascript

31st Jan 2021, 3:44 PM
Lakshmi Priya
Lakshmi Priya - avatar
2 Answers
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.
31st Jan 2021, 6:37 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
by reference: variable container. by value: variable content.
31st Jan 2021, 7:21 PM
visph
visph - avatar