Deep clone sao chép đệ quy toàn bộ nested values mà không giữ reference gốc.
js
function deepClone(obj) {
if (obj === null || typeof obj !== 'object') return obj;
const clone = Array.isArray(obj) ? [] : {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) clone[key] = deepClone(obj[key]);
}
return clone;
}Lưu ý: không handle Date, RegExp, Map, Set, circular refs.
Production dùng structuredClone() hoặc lodash.