OutputNot attempted
Default parameters vs passing the object
const value = { number: 10 };const multiply = (x = { ...value }) => { console.log((x.number *= 2));};multiply();multiply();multiply(value);multiply(value);multiply({ ...value });Spaces and quote style don’t matter · write a thrown error as TypeError
Ctrl Enter
Show answer & explanation
The expected output comes from actually running the snippet; opening this shows it next to the explanation.
A default parameter is evaluated on EVERY call where the arg is undefined, so each default is a fresh copy of {number: 10} → 20, 20. Passing value itself mutates the shared object → 20, then 40. The last call copies the now-mutated value (40) → 80.