clean-code-javascript icon indicating copy to clipboard operation
clean-code-javascript copied to clipboard

pass by value is already default behavior of functions

Open lumosmind opened this issue 4 years ago • 1 comments

Destructuring also clones the specified primitive values of the argument object passed into the function. This can help prevent side effects. Note: objects and arrays that are destructured from the argument object are NOT cloned.

Primitive arguments of functions are already cloned. This is not es6 object deconstruction specific behavior.

let a = 5;
const increment = (num)=> ++num;
console.log(increment(a));
console.log(a);

lumosmind avatar Dec 05 '20 17:12 lumosmind

If the function accepts an object as a parameter, just the reference will be cloned.

meblum avatar Feb 19 '21 04:02 meblum