Exercises: Array and Object Spread Syntax - Javascript In Depth

  Рет қаралды 1,269

Tech with Nader

Tech with Nader

Күн бұрын

Пікірлер: 10
@simplyskandi5973
@simplyskandi5973 2 жыл бұрын
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!
@TechWithNader
@TechWithNader 2 жыл бұрын
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 😄
@khanittaajay3932
@khanittaajay3932 2 жыл бұрын
Hello Nader! Great exercises! Thank you!
@TechWithNader
@TechWithNader 2 жыл бұрын
Thank you very much! Glad you’re enjoying them and learning 😊
@Abulkhair1995
@Abulkhair1995 Жыл бұрын
const superhero = { name:"Bruce Wayne",allies:"Batman",Universe: "DC",Happy:false,enmies:["Catwoman","Joker","Sucker"], bestMOvies:{title:"Dark Knight",ranting:95} } const copy = { ...superhero } const copy1 = { ...superhero.enmies,3:"Poison ivy" } const copy2 = { ...superhero.bestMOvies, year:200000 } copy2.year=2008; console.log(superhero); console.log(copy);
@KRAKENBACK..
@KRAKENBACK.. Жыл бұрын
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
@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..
@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
@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)
Destructuring Syntax - Javascript In Depth
31:50
Tech with Nader
Рет қаралды 1,5 М.
Array and Object Spread Syntax - Javascript In Depth
41:50
Tech with Nader
Рет қаралды 1,9 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 79 МЛН
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,6 МЛН
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 29 МЛН
TypeScript Full Course - From Beginner to Advanced
3:54:02
Tech With Tim
Рет қаралды 81 М.
User Profile App - Project #2 - React from Confusion to Clarity
57:32
Exercises: Switch Statement - Javascript In Depth
24:14
Tech with Nader
Рет қаралды 731
Sets - Javascript In Depth
15:23
Tech with Nader
Рет қаралды 1,6 М.
DNS, IP Addresses & Ports - Rest APIs In Depth
32:16
Tech with Nader
Рет қаралды 2 М.
JS Spread Operator: How It Works & Why I Love It
16:31
Colt Steele
Рет қаралды 76 М.
Golang: The Last Interface Explanation You'll Ever Need
17:58
Flo Woelki
Рет қаралды 24 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 79 МЛН