Welcome to my channel! Here I talk about several software engineering aspects, especially on the technology, programming and design tips and techniques. For my blogs, check out: strongcoffeecode.wordpress.com/
The way you explained sir I will never forget. kindly add more videos . because in your playlist I can see only three videos .please create more videos sir.
let developer1 = { name: 'Nilanjan' } let developer2 = Object assign ({}, developer1); developer2. name = 'Vishnu'; console. log (developer1); //Nilanjan console. log(developer2);//Vishnu My doubt is here it doesnt change the original object ie developer1, so how it is shallow copy? as shallow copy defines if any changes made in the new object will affect in the original object
You should explain how to deep copy without a library. The following is a snippet from ChatGPT: function deepClone(obj) { // Handle non-object types and null if (obj === null || typeof obj !== 'object') { return obj; } // Create a new object or array based on the type of the input object const clone = Array.isArray(obj) ? [] : {}; // Iterate over each property in the input object for (let key in obj) { if (obj.hasOwnProperty(key)) { // Recursively deep clone nested objects and arrays clone[key] = deepClone(obj[key]); } } return clone; } // Example usage: const originalObject = { name: 'John', age: 25, address: { city: 'New York', country: 'USA' }, hobbies: ['reading', 'traveling'] }; const clonedObject = deepClone(originalObject); console.log(clonedObject);
They might be traced and linked to each other, but they maintain their own independence. Basically, objects have no hierarchy. Nothing like a child object and a parent object, even though one object can be a property of another