deep clone and shallow clone in javascript code example

Example 1: javascript deep clone

var cloned = JSON.parse(JSON.stringify(objectToClone));

Example 2: js shallow copy

Object.assign({}, obj); // ES6 shallow copy

Example 3: shallow copy vs deep copy js

/*

Search Results
Featured snippet from the web
A deep copy means that all of the values of the new variable
are copied and disconnected from the original variable. 
A shallow copy means that certain (sub-)values are still connected
to the original variable. To really understand copying,
you have to get into how JavaScript stores values


/*

Tags:

Misc Example