Exercise-03 really helped me understand the concept of shallow copy vs actual copy. I have always found this concept super confusing and sort of glazed over it. Thank you for this brilliantly thought-through qs!
@TechWithNader2 жыл бұрын
Thanks! I’m glad it was helpful! It’s a really tricky concept and will bite us really hard in subtle ways as we build more complex program and deal with things like state management later 😄
@khanittaajay39322 жыл бұрын
Hello Nader! Great exercises! Thank you!
@TechWithNader2 жыл бұрын
Thank you very much! Glad you’re enjoying them and learning 😊
While doing exercise 3 the way I did it was completley wrong LOL I thought it was asking us to create another copy but with only enemies and best movies, So i did / let enemies = superhero.enemies; // let bestMovie = superhero.bestMovie; // // console.log(enemies); // // console.log(bestMovie); // const superheroCopy = { enemies: enemies, bestMovie: bestMovie }; // console.log(superheroCopy); // superheroCopy.enemies.push("Poison Ivy"); // superheroCopy.bestMovie.year = 2008; But then watching the solution I totally understand how we were able to create a copy of the whole object and overwrite some of the properties to add different primitives and not change the original object. I was wondering why when solving the problem that this felt more of like a .push exercise and now I realize I was doing something entirely different then the question was asking 😂😂
@TechWithNader Жыл бұрын
Haha all good! Some of these instructions are extra long and I could probably find a way to make them less confusing 😂 Glad you see how to do it both ways though!
@KRAKENBACK.. Жыл бұрын
is the reason the shallow copy gets to alter its properties because we are adding/changing a primitive? Would it have changed the original if we were adding/changing a non primitive that could've been inside of the object?
@TechWithNader Жыл бұрын
@@KRAKENBACK.. Yeah generally primitives are always copies no matter what or where they are. Everything else is always a reference, so changing it in one spot will change it elsewhere and we don't copy when moving/referencing them in different spots (including spread)