how to create shallow copy and deep copy in js code example

Example 1: how to make a deep copy in javascript

JSON.parse(JSON.stringify(o))

Example 2: javascript '=' operator shallow copy or deep copy

// The '=' operator in javascript can serve the purpose of shallow vs
// deep copy.

// The '=' operator in javascript will assign deep copy to primitive 
// data types. For example:
let a = 10;
let b = a;
b = 4;
console.log(a);
// Output: 10
console.log(b);
// Output: 4


// The '=' operator in javascript will assign shallow copies to
// non-primitive data types. For example:
let a = ['a','b','c','d','e','f','g'];
let b = a;
b.pop();
console.log(a);
// Output: ["a","b","c","d","e","f"]
console.log(b);
// Output: ["a","b","c","d","e","f"]