Yeah man, you did a great job at explaining this stuff, I thought I understood it before but now I really understand it. God bless you 100 man. Peace.
@akshhatsrivastava19724 жыл бұрын
That stack and heap explanation was very insightful. Thank you!
@naythaniel7 жыл бұрын
The short version, not 20 minute version of this, is that primitives (things that aren't containers for multiple separate values) make copies when passed to a function; while objects (containers for multiple separate values) make *references* to the object when passed to a function. In other words, when something is likely to be relatively small, it's okay to make a copy, but when it can potentially be enormously large, you just say where the thing is. Remember, primitives = copies && objects = references (which means addresses || pointers).
@prathameshsawant8436 жыл бұрын
You can use destructuring to copy object. Although for the array that is stored as a property inside object you will have to use destructuring again.
@augiefash22394 жыл бұрын
Brilliant. I've spent the last 3 days trying to grapple with / grasp this, and you pretty much just saved me. Thanks bud!
@jeewanmaharjan27124 жыл бұрын
You deserve award for this explanation .
@inote42664 жыл бұрын
@@prathameshsawant843 that's called deep cloning
@rickvian4 жыл бұрын
I recommend go through this 20 minutes cause it is worth it!
@88spaces3 жыл бұрын
Max, you're very good at explaining complex topics in a simple way that makes them easier to understand. Thanks for the video.
@samirergaibi8746 жыл бұрын
Thank you for this visual explanation, really made me understand. The pictures of the Stack and Heap sure helped as well ! :)
@eruston5 жыл бұрын
Very good explanation. I remember in C++, for every constructor, you have to have a destructor, otherwise the objects will 'pile up' on the heap = memory leak.
@paulparton4045 жыл бұрын
A shorthand way to clone the object and its array with the spread operator const person3 = { ...person2, hobbies: [ ...person2.hobbies ] }
@yezhang19275 жыл бұрын
I think it works if you just use this: const person3 = { ...person2}
@brookspatrader5 жыл бұрын
@@yezhang1927 No, with your solution, it not works. Paul's right.
@bhupenderKeswani3 жыл бұрын
A better way to solve this is const person3 = JSON.parse(JSON.stringify(person2));
@JuanFVasquez7 жыл бұрын
Wow Max, I thought I knew what primitive and reference types were. You simply took these concepts to a whole new level! I didn't know about the stack and the heap at all! Thanks for explaining these amazing concepts.
@academind7 жыл бұрын
Thank YOU Juan for such an awesome feedback, really happy to read comments like yours :)
@nuttaphonr.64983 жыл бұрын
Thanks for concepts about reference vs primitives type and heap/stack too! 3:39 string is primitive (copy by value) 6:47 object ,array are references type 7:05 primitives are store on stack 7:35 references are store on heap (take longer to access, store bigger amount of data) 8:40 stack (store like stack 'push on top') 9:16 heap (store pointer) 10:48 it assign a pointer not value 14:50 Object.assign create new object and merge with existing one 16:07 Object.assign doesn't deep clone 17:26 may use Lodash to clone instead 19:04 copy array
@dheerajmantena33076 жыл бұрын
Object.assign({},deepMind.Slice()); Superb in depth explanation You are the best for ever max . Thanks again
@academind6 жыл бұрын
Thanks a million for your fantastic feedback Dheeraj, so cool to read that you like my videos :)
@sydneyhill6552 жыл бұрын
The stack and heap explanation and illustration for these concepts made lightbulbs go off for me. Thank you.
@cdac16457 ай бұрын
This is the best and most concise explanation I have seen on KZbin. Thanks
@ihortsarenko31195 жыл бұрын
amazing as always. Thank you, Max. Maybe it could be a little bit hard for newbies, but that's the best explanation I saw for about a year of learning JS
@academind5 жыл бұрын
Thanks a lot Irop!
@berkan85184 жыл бұрын
Brother ! I really respect you. You are the best educator of all time. If you weren't born i couldn't understand these things because there is noone explain these things very specific and easy as you. Thanks
@tezdogs2 жыл бұрын
This actually helped me understand how to use pointers and reference values in C++, too! Thank you Max! :D
@pushpaaji7 жыл бұрын
Recently started angular. Getting issues just because of object and arrays are getting changed. you saved me. thanks for the great tutorial.
@academind7 жыл бұрын
Awesome to hear that, thanks for your great review!
@Concentrum7 жыл бұрын
I'm impressed by your fluent and well-prepared explaining. your gestures are also very entertaining haha, thanks for doing what you do.
@academind7 жыл бұрын
Nice to hear that, thanks so much ;)
@bronstein007 Жыл бұрын
Great video diving deeper into reference types and reference values! I was so tired of just hearing people say, "it's a reference type, they aren't the same". Actually seeing how it works in the stack and heap memory space was SO valuable. Question about Object.assign and slice methods for copying objects and arrays: Would an equivalent (and potentially cleaner way of doing it) just be using the spread operator for both? Thanks!
@MJ-fu4yc5 жыл бұрын
Max, I got that Udemy course about nodeJS, I know basics of oop, but came here only to refresh my knowledge, I cant help commenting that you are great lecturer !
@academind5 жыл бұрын
Thanks so much for your awesome support here and on Udemy Marcin!
@naqeeburrahman47094 жыл бұрын
That makes sense. thank u. Earlier I was bit confused why u took long steps to copy in one example of your react course.
@baharehbadiei76983 ай бұрын
Perfectly and deeply explained! Loved it. Thanks :)
@sunilpatel65427 жыл бұрын
Somethime JSON.stringfy and JSON.parse also works for cloning object
@dayvie95177 жыл бұрын
But it is a really roundabout way to do it. You want to copy an object, no to make an object to a string and then get an object from a string which is more demanding.
@yuriiyakhnytsia22922 жыл бұрын
Thanks a lot, now I have a clear understanding of what happens with the state in redux, and now I knew that I have a great number of issues with the store of my project, just because I copied the state with spread (...) operator. But I have a state not only with primitive types but with objects and arrays either, and in the future, it may cause problems.
@xseeginfo50645 жыл бұрын
best primitive and reference tutorial forever
@academind5 жыл бұрын
Thank you, awesome to read that!
@dhanooshbargav72153 жыл бұрын
You did the explanation as best as you could. Thanks a lot!
@utsavkumar43816 жыл бұрын
Good that you covered the subject with Stack and heap explanation. Thanks Max :)
@academind6 жыл бұрын
Thanks a lot for your great feedback Utsav, really appreciate that :)
@jason-pacini3 жыл бұрын
In case anyone is wondering, you can make a deep copy by doing: let newObj = JSON.parse(JSON.stringify(oldObj))
@gabrielhernandez84577 жыл бұрын
Hey Max!, really nice udemy courses that you have... greetings from Chile!
@academind7 жыл бұрын
Really happy to hear you're liking them Gabriel - thanks for your amazing feedback!
@dominiquefortin53455 жыл бұрын
For having written a javascript compiler/interpreter, I think that talking about the stack in javascript is using a low level metaphor that does not have it's place. All the function parameter are evaluated and the results are put in a structure called the closure that will be use to evaluate the function. If function parameters were alway on the stack then when returning a function object, you would lose all the parameter values of the enclosing function. At best, the stack is used as an optimization for this closure if there is no reference of the closure captured in a function instantiation. The location of the content of a closure is implementation specific.
@DespicariPirates Жыл бұрын
JSON.parse(JSON.stringify(object)) beter way to deeply clone objects
@aneshkl5 жыл бұрын
Thank you so much for this video. It was explained so well. I don’t think I’ll ever get confused between the two.
@academind5 жыл бұрын
Happy to read that the video was helpful for you Aneesh, thank you :)
@msalah52144 жыл бұрын
Thank u for this video. I was wondering before how could i handle this cases in my code. Now its very clear about the object references. You are very helpfull... thank youu..
@OmarOnAWave3 жыл бұрын
Amazing explanation man ! wow you really have a talent to break things down to understandable bits
@sourishdutta96006 жыл бұрын
You all time amaze me.You the best I have ever seen.You could also explain Object.freeze() to this lecture.Anyways mutable vs immutable great.I am a big fan of yours.Share your knowledge Sir Max.
@sashab44322 жыл бұрын
The explanation was soo good. Thank you!
@HaifengZhu-pn3uq6 ай бұрын
Max' content is always great
@yuvakishoredommaraju10925 жыл бұрын
we can use the following method for deepCopy var secondPerson = JSON.parse(JSON.stringify(person)) instead of using Lodash library var refpers = { 'name': 'YUVA', 'age': 25, 'hobbies': ['playing', 'coding'] } console.log(refpers); var deepCopy = JSON.parse(JSON.stringify(refpers)); var shallowCopy = refpers; refpers.name = "yuvakishore"; refpers.hobbies.push('roaming'); console.log(deepCopy, shallowCopy, refpers);
@celestia13 жыл бұрын
Dude you are very useful. Become a teacher cause you clarified it very well.
@sergiyrudenko9055 жыл бұрын
You can learn c++ pointers to have better understanding of how it's linked in memory. c++ it's very good language to understand how memory work's. I used a lot this concept in 3d modeling for copying object or to make an instance(linked copy) of object.
@huzeyfetas2 жыл бұрын
I have 1.5 years of experience as a software developer. I watched this video about 1.5 years ago. and i said ok i got it. now i'm watching it again and now i'm saying "okay now i get it". I came here from Max's svelte.js course. why do we need to use assignment operation in svelte which does not use push to work with arrays, now everything is very clear. I hope there is no problem in my project where I used the object.assign operation almost on the ground 1 year ago while cloning an object :) Now I understand the value of the deep copy operation. Seeing the questions and answers on stackoverflow I realized that this is a real problem. (My english is not good enough, I hope I was able to express myself. )
@jtaylor8606 Жыл бұрын
Your comment makes perfect sense. Nearly every comment on here is saying how simple this explanation makes it to follow but, honestly, I doubt if even 50% of those people really understand it properly. I've watched it multiple times and there are still a couple of parts that I don't think I'm understanding fully.
@aabid33755 жыл бұрын
I am completely enjoying Your Nde.js course
@academind5 жыл бұрын
Happy to read that Abidul, thank you for your support!
@muradprohere Жыл бұрын
happy to learn from you mr max thank you for the explanation
@naeliesuttra8 ай бұрын
In the example with person and secondPerson, why isn't the same pointer that gets created for person used when we do var secondPerson = person? Is it because if the first variable gets deleted, the first pointer disappears too and we need something "left" to point to the object in memory?
@sandeshjadhav21884 жыл бұрын
Thank you for this visual explanation, really made me understand.
@maltegb3 жыл бұрын
I do not understand why JavaScript doesn't have a built-in deep-copy-function for objects, is it so hard to implement?
@prabhasthakur97762 жыл бұрын
One silly doubt, when name variable is updated from 'Max' to 'Chris' then on the stack whether the 'Max' is replaced to 'Chris' or a new copy of 'Chris' is made on top of the stack? Thanks.
@TheSkis7 жыл бұрын
Great explanation! Thorough and covered all feasible cases
@academind7 жыл бұрын
Thanks a lot for your nice feedback Ben!
@pantelisvasileiadis28584 жыл бұрын
thank you! cleared things up in my head
@GroudFrank2 жыл бұрын
Was this nonesense by design or was this a bug they couldn't squash, so they decided to call it a feature? Thanks for your explanation btw! It helped👍🏿
@miladhp5690 Жыл бұрын
you can create a shallow copy without reference only if you use `const copy = {...obj}` instead of `Object.assign({}, obj)` :)
@piters1017 жыл бұрын
If we want to copy deep object (and we don't have any functions in object) we can use easily: var copyObject = JSON.parse(JSON.stringify(obj));
@academind7 жыл бұрын
That's indeed a nice trick. Of course even easier with ES6/ES7 and object spread operators. But I might dive into that in the future
@nadiaharrismartinez2 жыл бұрын
That was so helpful. Great explanation. Thanks so much!
@aabid33755 жыл бұрын
How awesome is the explanation...Yup it was little bit longer but i can asure you of getting it if u watch it for the second time. #thanksMaxy
@karnpratapsingh88602 жыл бұрын
awesome explanation! Really helpful. Thanks for it.
@boristheblad Жыл бұрын
Nice to know that, well explained. thanks!
@Marcel-dt5du6 жыл бұрын
Thank you! Did I understand you correctly at the end; .slice() also does _not _create a new deep copy of an object in the case of an array of objects?
@fallen_turbo Жыл бұрын
Amazing, also I think we can use JSON functions to create deep clones, JSON.parse(JSON.stringify( object/array name ));
@krunoslavbanovac43567 жыл бұрын
Very well explained. Missed your vids Max.
@academind7 жыл бұрын
But my videos were never paused? Anyways, happy to hear you liked this one!
@krunoslavbanovac43567 жыл бұрын
But they were paused for me. After watching your React and Redux tuts, thanks to you, I was too busy working on a project :D
@petrockspiracy31205 жыл бұрын
That was a fantastic explanation and use of example.
@academind5 жыл бұрын
Thank you!
@waseemansar40777 жыл бұрын
wow you make this concept very simple. Thanks Max
@academind7 жыл бұрын
Happy to hear that this was helpful! :)
@BeeshoStudying Жыл бұрын
thank you for the video and the simple explanation
@rohil30233 жыл бұрын
Great explanation.I think i understood most of what you said 👏
@shibleesaidul49634 жыл бұрын
In javascript stack tells us where we are in the program & all variables and other objects are stored in heap memory. so whether it is primitive or reference type all stored in heap, isn't it???
@abhishekshimpi2143 жыл бұрын
Thank u so much dude u completely cleared my concept
@michelleBSkiLLz2 жыл бұрын
nice and easy explanation! Thanks!
@nathnolt11 ай бұрын
Nowadays, you would use structuredClone(value) instead of JSON.parse(JSON.stringify(value)) for deep copies.
@codebuilders90814 жыл бұрын
that was a pretty nice explaination of a complex concept.
@academind4 жыл бұрын
Happy to read that, thank you!
@NICHLE. Жыл бұрын
Hi Max, thanks for great tuitorials. I am just wondering why didnt you mention spread operator as option to object.assign method because of its deep-cloning ability
@andrew54074 жыл бұрын
Does the Array pointer live on the stack or in the heap ?
@sachithradilshan96736 жыл бұрын
it is a one of best explanation sir.you have well planned the example and content.keep doing.
@academind6 жыл бұрын
It's just fantastic to read that, thanks a lot!
@sumeetsood2326 жыл бұрын
Thanks Max. Great Video. Can you please show how object is stored in memory if object has a property that gain is a object or array, like you showed how object is stored in memory.
@degreman2 жыл бұрын
Thats a Good explanation, thanks to you
@jasnanajeem91214 жыл бұрын
at 11:34, why didnt the names in the console.log of other two [object object] change to chris??????????????//
@silambarasanr.d26042 жыл бұрын
What if we use the Spread operator to copy the object to a new object?
@paxdriver2 жыл бұрын
Introducing the spread operator lol now I use it for everything
@TechSquidTV7 жыл бұрын
Amazing video as always. Sharing on Twitter!
@academind7 жыл бұрын
Awesome, thanks so much!
@chrsbll7 жыл бұрын
Extremely well explained. Thank you.
@academind7 жыл бұрын
Really happy to hear that, thanks so much Chris!
@tymothylim65503 жыл бұрын
Thank you very much for this video! :) It was very interesting and I learnt a lot!
@nigelhing66055 жыл бұрын
Just a silly question, but how do you record yourself to show up on the right hand side of the screen? I've seen this technique a lot and I want to know how to do it too :-)
@academind5 жыл бұрын
Not a silly questions Nigel - we are sitting in front of a greenscreen and record ourselves + the screen. This is the hardware: kzbin.info/www/bejne/gqDUp56tqbF1iJo And this is how we edit the videos: kzbin.info/www/bejne/iKK9oqCKirSUi9E
@ХристоСтанков-о6к6 жыл бұрын
Awasome. The best explanation!
@academind6 жыл бұрын
Thank you so much, I'm glad you liked it!
@OscarCedano Жыл бұрын
Thank u bro! This video really helped me!
@anythgofnthg1545 жыл бұрын
if you put name = 'Chris' above var secondName = name; , console.log(secondName) would output Chris. I don't see how there are two names in memory. Also, instead of the last line being console.log(secondName), if he'd have written console.log(name) the output would have been 'Chris' not 'Max'. It seems to me that the variable was reassigned in memory, not stored twice. Am I wrong here? Maybe I'm not understanding him correctly.
@rohancherry6 жыл бұрын
excellent explanation, thank you Max.
@academind6 жыл бұрын
So happy to read that Ravi thank you very much!
@sandeeprao16517 жыл бұрын
Love the way you explain. Thanks Max. Also, halfway through your Angular4 Udemy course. Loving it.
@academind7 жыл бұрын
Really awesome to hear that Sandeep, thanks for your feedback! :)
@aakritigoyal14323 жыл бұрын
U explained it so well❣💯
@swapnilbhargava29274 жыл бұрын
Max, you are simply awesome. I love you 😘
@DharmendraSingh4ever3 жыл бұрын
Thank you very much... You are great ✌🏼👍🏼
@harshilparmar90764 жыл бұрын
As always Thank you so much !! Can you make a video on how to understand the code and contribute to js repo on Github
@emanfinding26036 жыл бұрын
Pretty clear, Thanks Max!
@academind6 жыл бұрын
Very happy to read that Eman, thank you for your comment!
@ronidey3806 жыл бұрын
Thank you so much... Nobody could explain it better than this😊
@academind6 жыл бұрын
Thank you very very much for your wonderful feedback Roni, this honestly means a lot to me :)
@djelasrca8091 Жыл бұрын
Super useful. Thanks
@adamscantley7 жыл бұрын
This is absolutely fantastic. Thank you!
@academind7 жыл бұрын
Thanks so much Adam, I'm happy you're liking it!
@pankajsharma98014 жыл бұрын
Thank you so much. You clear lot of important points for me. 😊👌
@fishworld20214 жыл бұрын
kzbin.info/www/bejne/iZ-7g2mhjZaGp6M
@davida.75866 жыл бұрын
Very good explanation. Thank you!
@academind6 жыл бұрын
Great to read that you like it David, thank you!
@sharriceowens9139 ай бұрын
thank you so much you have a new subscriber
@vs5993180267 жыл бұрын
Thanks Max, you explained so well !!!! It helps me a lot !!
@academind7 жыл бұрын
Thanks a lot Jack, great to hear that :)
@vs5993180267 жыл бұрын
I'm actually taking your ES6 course on Udemy, and I think you should add this to the intro section and it will be more clear. I know you explain the same thing while explaining the ES6 features but that visual ppt really helps me to understand primitive and reference deeply !!! Anyways, 5 stars on the ES6 course and moving on to your Vuejs course !! :)