ryanmcdermott / clean-code-javascript

:bathtub: Clean Code concepts adapted for JavaScript
MIT License
91.54k stars 12.29k forks source link

pass by value is already default behavior of functions #329

Open lumosmind opened 3 years ago

lumosmind commented 3 years ago

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);
meblum commented 3 years ago

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