Does Javascript Handle Objects By Reference Or By Value?
I have this code var myObjects = {}; //global variable //Later on in the code: for (i in myObjects) { var obj = myObjects[i]; process(obj); } function process(obj) {
Solution 1:
Primitive variables are passed by value in JavaScript, but objects are passed by reference.
Source and further reading:
Solution 2:
JavaScript is pass by value, as has been clarified in an earlier question. (Someone with more powers should mark this as duplicate--the answers here are incorrect.)
Solution 3:
all non-object variables are pass-by-value afaik..
Post a Comment for "Does Javascript Handle Objects By Reference Or By Value?"