I've got this code:
function margeOptions(options, passedOptions) {
options = Object.assign(options, passedOptions);
}
let passedOpts = {a: true};
let opts = {a: false};
margeOptions(opts, passedOpts);
console.log(opts); // as expected returns {a: true}
but when I change function a little bit, like this:
function margeOptions(options, passedOptions) {
options = Object.assign({}, options, passedOptions);
}
let passedOpts = {a: true};
let opts = {a: false};
margeOptions(opts, passedOpts);
console.log(opts); // this time returns {a: false} <-- !
So what really happened in here?
formal_parameter =in a function doesn't affect the actual parameter in any way