js always call by value
Does Javascript pass by reference?
My 2 Cents.... It's irrelevant whether Javascript passes parameters by reference or value. What really matters is assignment vs mutation. I wrote a longer, more detailed explanation here ( Is JavaScript a pass-by-reference or pass-by-value language?) When you pass anything (Whether that be an object or a primitive), all javascript does is assign a new variable while inside the function...
https://stackoverflow.com/questions/13104494/does-javascript-pass-by-reference
the reference itself is passed by value
Â
function replace(ref) { ref = {}; // this code does _not_ affect the object passed } function update(ref) { ref.key = 'newvalue'; // this code _does_ affect the _contents_ of the object } var a = { key: 'value' }; replace(a); // a still has its original value - it's unmodfied update(a); // the _contents_ of 'a' are changed
Â
Â
Â
Â
Â


Seonglae Cho