Nice summary!
I'd like to add a tiny bit to the nested array example, that when you rest-spread an array, if that array has another nested array as its element, what gets shallow-copied is the reference to the original nested array:
let nestedArray = [1, [2], 3]; let arrayCopy = [...nestedArray]; // arrayCopy == [1, ref, 3];
thus creating the mutation effects.
Yup! In those cases, if you want a true copy, you will need to do a deep clone. Thanks for sharing!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice summary!
I'd like to add a tiny bit to the nested array example, that when you rest-spread an array, if that array has another nested array as its element, what gets shallow-copied is the reference to the original nested array:
thus creating the mutation effects.
Yup! In those cases, if you want a true copy, you will need to do a deep clone. Thanks for sharing!