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
//recursive method to create deep copy | |
function deepCopy(obj) { | |
if (null === obj || 'object' !== typeof obj) return obj; | |
switch (obj.constructor) { | |
case Boolean: | |
return new Boolean(obj); | |
case Number: | |
return new Number(obj); |
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 originalObject = { | |
string: 'primitive string', | |
stringObj: new String('string obj'), | |
number: 100, | |
numberObj: new Number(100), | |
bigInt: BigInt("9007199254740991"), | |
nan: NaN, | |
array: [1, 2, 3], | |
arrayObj: new Array(2), | |
bool: false, |