Interesting discussion! I think what’s important to remember (besides the notion of an object’s memory address being passed—sort of a value with a reference mwa-ha-ha—is that you cannot reassign, but you can add or even mutate the properties:
function test(o) {
o = {newobject: ‘yo’};//reassignment: won't take affect once call completed
}let o2 = {foo: ‘o2 here’};
test(o2);
console.log({after_call: o2}); //outputs: after_call: {foo: “o2 here”}function test2(o) {
o.newprop = ‘a new property was added in function’;//can add properties though. WILL take affect once call completed
}
test2(o2);
console.log({after_call: o2});//outputs: after_call: {foo: “o2 here”, newprop: “a new property was added in function”}
Easy enough to test for yourself as well ;)
Additionally, the reason to know this is to purposefully create functions that are either destructive (less “safe” but more efficient if you really really need that), or return a copy non-destructively. Probably, you’d want to favor the later unless/until you find the need to optimize since mutating goes against the generally functional spirit of JavaScript programming (opinion of course).