Javascript - [why?] Assigning A Variable To An Object
Why is it that when I assign a variable to an object and make a change to that variable it also changed the objects? For example: c = 26; a = b = c; a += 1; a // 27 b //
Solution 1:
When you assign an object to a variable, it just makes a reference to the original object, it doesn't make a copy. So all the variables refer to the same object.
Post a Comment for "Javascript - [why?] Assigning A Variable To An Object"