Implement a function deepClone(value) that creates a deep copy of a JavaScript value.
The function should:
null, boolean, number, string, Array, Object).Example
const obj1 = { user: { role: "admin" } }; const clonedObj1 = deepClone(obj1); clonedObj1.user.role = "guest"; console.log(obj1.user.role); // "admin" const obj2 = { foo: [{ bar: "baz" }] }; const clonedObj2 = deepClone(obj2); obj2.foo[0].bar = "bax"; console.log(clonedObj2.foo[0].bar); // "baz"
JavaScript Function
No test results yet
Click "Run" to execute tests