JS passed by copy of a reference
🚓

JS passed by copy of a reference

Creator
Creator
Seonglae Cho
Created
Created
2020 May 7 8:48
Editor
Edited
Edited
2021 Apr 21 6:46
Refs
Refs
js always call by value
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
 
 
 
 
 

Recommendations