|
|
|
|
|
by bryanrasmussen
694 days ago
|
|
I guess technically it's passed the reference to the string right, so if I say a = "stringA" there is a reference to "stringA" and that is assigned to a if I then say a = "stringAA" there is another reference created for "stringAA" and assigned to a, while "stringA" is sitting around somewhere waiting to be garbage collected in a few milliseconds - that's way complicated to think about and not sure if I haven't messed it up. Easier to just say pass by value and forget about it. OR make all your variables consts and then it don't matter. |
|
Where it matters is in passing arguments to a function call. If you pass 42, it’s not mutable so incrementing, or doing anything, will not modify the original variable you passed-in. For a reference, using = will assign a new value (not change the original) but modifying the referenced object like, say a.b = 5 WILL change the original object.
It’s not really “pass by reference” that a C/C++ developer would understand but it seems to be the term that has stuck.