Last active
November 22, 2024 11:20
-
-
Save mgarratt/2edfaa36f5e6d4fae4a93c0e299c6454 to your computer and use it in GitHub Desktop.
JS is odd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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