[Javascript] Pass by Reference or Pass by Value?
Connection between variable, value and memory A variable is just a pointer to a location in memory. When you create a variable, your program allocates a space in memory, remembers it so that you can assign value to it and retrieve the value when you want. The 'reference' in 'pass-by-reference' refers to memory location. The 'value' in 'pass-by-value' refers to the actual value in the memory location. Why does this matter? When you use pass-by-value, it means that any argument you pass to a function only have their values copied and transferred to parameters inside the function definition. In other words, the parameters inside the function are not the same as the variables you passed in as arguments. When I say the 'same', even though their value is same, if you change one of them, the other will not change (if it is pass-by-reference, the other will change). Below is an example of pass-by-value: // A pseudo-code example of pass-by-va