Implement a deepClone
utility that returns a deep-copied version of any plain JavaScript data (objects, arrays, and primitives).
function deepClone<T>(value: T):
string
, number
, boolean
, null
, undefined
, bigint
, symbol
){}
or Object.create(null)
)Date
, RegExp
, Map
, Set
, functions, DOM nodes) should be returned as-is (shared reference).const original = {
user: "Alice",
scores: [1, 2, 3],
};
const copy = deepClone(original);
copy.scores.push(4);
console.log(original.scores); // [1, 2, 3]
console.log(copy.scores); // [1, 2, 3, 4]