A great introduction to shallow vs deep cloning in JavaScript.
Be careful using JSON parse/stringify to deep clone as it does not support some JavaScript features when used to clone objects. Date objects will convert to strings. Functions, symbols, and undefined are also not correctly converted over.
Just a couple of things to watch out for if one is looking for a proper deep clone. Better off to use something like lodash cloneDeep for correctness and performance reasons.
Francesco Strazzante
Web Developer
Great and useful post! Thank you Chris. π Years ago I remember I used cloneDeep: the function from lodash, but it tooks a while to understand the problem. This pointer creation when use "=" it's not widely known unfortunately.