Skip to content

Instantly share code, notes, and snippets.

@mgarratt
Last active November 22, 2024 11:20
Show Gist options
  • Save mgarratt/2edfaa36f5e6d4fae4a93c0e299c6454 to your computer and use it in GitHub Desktop.
Save mgarratt/2edfaa36f5e6d4fae4a93c0e299c6454 to your computer and use it in GitHub Desktop.
JS is odd
const myMutator = (theObj) => {
const objClone = {...theObj};
objClone.primProp = 2;
objClone.objProp.value = 'mutated!';
};
const myObj = {
primProp: 1,
objProp: { value: 'original' }
};
myMutator(myObj);
console.log(myObj);
/* Output:
{
primProp: 1
objProp: {
value: 'mutated!'
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment