JavaScript Visualized - Closures

Поделиться
HTML-код
  • Опубликовано: 27 окт 2024

Комментарии • 237

  • @theavocoder
    @theavocoder  2 месяца назад +57

    💡Understanding how functions interact with their surrounding lexical environment is very important when working with JavaScript, and it's really not as mysterious as it might seem at times haha. I hope this video was useful, visualizing the detailed inner workings of tools I'm working with always helps me understand concepts better.
    I only use Apple Keynote to create the visualizations! Implementation details might differ, this is just based on the ECMA spec. Different engines may implement smarter garbage collection strategies that mitigate issues related to retaining large scopes in closures (e.g. the fetchAllUsers example).

    • @codewithrahull9636
      @codewithrahull9636 2 месяца назад +3

      Please marry me😭

    • @mattpocockuk
      @mattpocockuk 2 месяца назад

      @@codewithrahull9636 Weirdo

    • @ksubramanyeshwara
      @ksubramanyeshwara 2 месяца назад

      Can we expect more advanced javascript and how javascript work behind videos? I would love if you release 2 or 3 videos a week. Thank You

    • @nitishjs5719
      @nitishjs5719 Месяц назад

      Can you please share link for ECMA spec you have referred to create above video?

    • @hieplevan1935
      @hieplevan1935 Месяц назад

      Hi Lydia, This is an amazing series about Javascript, Can I ask about Which Tool have been used for Virtualize this video?

  • @mattpocockuk
    @mattpocockuk 2 месяца назад +146

    Banger after banger

  • @ilisiedenis5877
    @ilisiedenis5877 2 месяца назад +49

    I'm so happy you're back. Please keep making these videos because they're the best out there. I hope you can eventually cover all JavaScript topics!

  • @amitavasengupta5580
    @amitavasengupta5580 2 месяца назад +5

    Ma'am you're doing fabulous job👏. No loud intros, no memes but original quality content which is class and extremely rare to find.

  • @filipbystricky7301
    @filipbystricky7301 2 месяца назад +9

    Wonderful video as always! I didn't realize closures hold a reference to the entire environment record: I hoped they were a bit smarter and only held references to the variables they actually used, allowing the GC to free the rest. Good to know!

    • @theavocoder
      @theavocoder  2 месяца назад +11

      Thank you! 🙏Just to get back to this - it actually depends on the implementation though; I cover the spec, but engines can use internal optimizations to eliminate "dead" variables even in such cases. V8/Chromium does this really well so in that case the issue with `fetchAllUsers` may not actually be an issue, but it's good to realize that that's not necessarily the default in all cases 😃

  • @ChesterSerenity
    @ChesterSerenity Месяц назад +2

    Best tutorials on javascript on youtube, keep the good work Lydia, you're really good at explaining things, love the humor in videos!

  • @TerabyteTy300
    @TerabyteTy300 2 месяца назад +16

    Yesss I’ve been waiting for this!! Thank you for keeping this incredible content going.

  • @SergeyChernyshev
    @SergeyChernyshev 2 месяца назад +5

    Great visual explanation of the concept that took me years to grasp back in a day - glad it will take less time for everyone who watches this! ;)

  • @toptrends88
    @toptrends88 Месяц назад +6

    As a fellow software engineer, I just wanted to say how much I appreciate your videos. They're incredibly well-done, and I only wish I had access to content like this when I was first learning these concepts. Being a visual learner, I used to draw out each concept to fully grasp them. Now, I recommend your videos to the junior devs and interns on my team-they've found them incredibly helpful. If possible, it would be amazing to see a 'JavaScript Visualized - Data Structures and Algorithms' series on your channel. I’ve been reading *Grokking Algorithms: An Illustrated Guide for Programmers and Other Curious People* by Aditya Bhargava, and I couldn’t help but think how amazing it would be to see those concepts brought to life in your visual style. Keep up the great work!

    • @brb639
      @brb639 Месяц назад +2

      You're correct. JS Visualized - DSA series would be awesome. Those are the main focus of SE interviews. It will be a great help.

    • @SEngMedia
      @SEngMedia Месяц назад +2

      That's a great idea. I'm also a visual learner. Looking forward to a DSA series with these cool visualizations.

    • @ProJSGrammer
      @ProJSGrammer Месяц назад +1

      1. Javascript data structures and algorithms by Sammie Bae,
      2. Data structures and algorithms with Javascript by Michael Mcmillan
      are also good. I would love to see a visualized explanation.

    • @theavocoder
      @theavocoder  Месяц назад +3

      @@toptrends88 good idea, I’ll try to create some :) I wrote a visualized book on all this years ago so it would be good to update!

    • @toptrends88
      @toptrends88 Месяц назад

      @@theavocoder Awesome. Looking forward to it.

  • @Kue_J
    @Kue_J 2 месяца назад +1

    The way you visualise these processes is amazing!
    Your videos are so helpful and I'm really looking forward to your next one.

  • @besizzo
    @besizzo 28 дней назад

    I find your explanations extremely useful. Your examples and quizzes at the end are just 🤌🏻 Please, keep making these videos about how JS works under the hood and other advanced topics 🙇🏼

  • @j2devstudio
    @j2devstudio 2 месяца назад +5

    Your videos especially these visualized series are the best !

  • @amahmuudd
    @amahmuudd 2 месяца назад +1

    Thank you for creating such a clear and informative video, Lydia Hallie! I would definitely recommend this video to anyone who wants to learn more about closures.

  • @Brandonverzuu
    @Brandonverzuu 2 месяца назад +1

    Your visualisations are a true inspiration! Love the simplicity and clarity they bring 👍

  • @madhuiitb-cse
    @madhuiitb-cse 2 месяца назад +1

    One of the best explanation on the closures.
    Always you are on the point.
    Please, do continue more.

  • @UncleJemima
    @UncleJemima 24 дня назад

    if only my actual CS courses were taught this clearly. thank you for putting the time/effort into create this wonderful explanation!

  • @АлександрБуравов-ф9я
    @АлександрБуравов-ф9я 2 месяца назад +2

    Lady, this is amazing! You have a talent for teaching. Visualization is your strong point. Thank you very much! ❤‍🔥❤‍🔥❤‍🔥

  • @ЕвгенийПетрушенко-ъ6р

    Thanks for the detailed explanation. I've always dreamed of a code visualization like this. I hope there will be more such videos.

  • @smjeelanibasha3048
    @smjeelanibasha3048 16 дней назад

    after watching your videos in the graphical representation . My mind is blow up.nice explanation, keep it up.

  • @hackytech7494
    @hackytech7494 2 месяца назад +2

    Thank you so much ❤. You teach with great visualizations, with great explanations and with great smile. Please keep posting such videos of JavaScript🙏

  • @caramel0sugar
    @caramel0sugar Месяц назад

    Ok, i haven't had the time to watch everything yet because i just discovered your video 10min ago but i already liked all your published videos and subscribed to your channel because my brain needs theis type of visual aid to understand better and i want to encourage you to keep doing as many videos as you can with programming concepts! I will now proceed to share your channel to my computer programming classmates

  • @chrislanejones
    @chrislanejones 2 месяца назад +1

    Yes, I love all of your diagrams, thank you so much for making these videos.

  • @Abated
    @Abated 2 месяца назад +1

    Really early on in my coding journey, but found this pretty fascinating. Hope to see more.

  • @chrislanejones
    @chrislanejones 2 месяца назад +1

    Yes, Lydia and her cool diagrams are back... Thanks for making these.

  • @_victorjansson
    @_victorjansson 2 месяца назад +1

    Never been explained better than this. Thanks!

  • @edgeeffect
    @edgeeffect 2 месяца назад

    I was just about to come over here and say I wished you'd do more of these... and there was a new one waiting for me. :) I've been doing JS for a long long long long time, so there MIGHT not be much I can actually learn from these videos but I still really enjoy watching them. I wish these had been around when I was learning, and I'd certainly recommend them to anyone who's getting to grips with JS. A lot of programming content on RUclips is very poor indeed but these videos are absolutely great! :)

  • @akj3344
    @akj3344 2 месяца назад

    Visuals and explanations are excellent. I have never seen tutorials presented this well.

  • @dedmanraizd
    @dedmanraizd 2 месяца назад

    Your videos continue to be the ones I look out for when learning JavaScript. Thank you Lydia we appreciate you.

  • @pixelhusten
    @pixelhusten 2 месяца назад

    Really well explained, if I ever have a junior in the team again, I'll refer him to your videos. What I really like is your visualizations, they are really well done and explain the processes under the hood even better.

  • @elyoaprogrammer
    @elyoaprogrammer 2 месяца назад

    Your videos are my happy day!!! They are like the a new chapter of my favorite show!!

  • @AryanSharma-lg7pn
    @AryanSharma-lg7pn 2 месяца назад +1

    "What an explanation! Please bring more content like this frequently."

  • @mjawale12345
    @mjawale12345 Месяц назад +1

    I love visual learning and thanks for your all videos , the special one for me was event loop.
    Your explanation is on point nd easy words , also the motions are awesome.
    I request you to have an video on nodejs internal working especially thread pool and async execution of threads.

  • @iamzeeali
    @iamzeeali 2 месяца назад

    Amazing video!!
    Please make a playlist for the all advanced topics in JavaScript(Hoisting, closures, this, FP, debouncing, throttling, polyfills, etc)

  • @ViktorShaparenko
    @ViktorShaparenko 2 месяца назад

    In my opinion, This is the hardest topic in JS, actually with execution context. I have to rewatch it one more time or even more. Thank you for the video.

  • @nettoaoquadrado
    @nettoaoquadrado Месяц назад

    I from Brazil, and I love your content!!! Please, continue with! It is so useful.

  • @saifullahrahman
    @saifullahrahman 2 месяца назад +1

    This channel is a goldmine

  • @sawekccc2211
    @sawekccc2211 2 месяца назад

    This is pure gold. Best JS series ever

  • @BornInBharat
    @BornInBharat 2 месяца назад +1

    Best explanation in the world! Keep making these videos. ❤

  • @mdahoradev
    @mdahoradev Месяц назад

    Awesome video!! Please keep bringing more bangers like this. These videos helps A LOT.

  • @REAL_Fred_Walker
    @REAL_Fred_Walker 2 месяца назад

    Your videos are best JavaScript visualizations on the internet by far

  • @rebelmachine88
    @rebelmachine88 2 месяца назад +1

    Another excellent video! You are so good at explaining this stuff.

  • @zephilde
    @zephilde 2 месяца назад

    Great work!
    I learned nothing because, hey 🤷🏻‍♂senior js dev, but I think this kind of crystal clear visual explanation is really great for beginers!
    I would have reduce headaches years ago if you had existed before Lydia !
    Continue this way! :)

  • @dream11tatyabichoo92
    @dream11tatyabichoo92 11 дней назад

    closure is just 2 pointer dereference, every closure variables is translated to these two instructions
    mov rax, [closure + [[Environment]]] ; First dereference: Get context object address
    mov rdx, [rax + 0] ; Second dereference: Get `x` from slot 0 in the context object

  • @veitkunz7058
    @veitkunz7058 7 дней назад +1

    Can you make a video about the differences between normal function and arrow functions? Because somehow there a different, but I have struggle to understand it. For example the handling of "this" differs and when a function is declared in an object, it is different also. With your videos, I understand very well, how this stuff works in depth.

  • @penguindrummaster
    @penguindrummaster 2 месяца назад

    Honestly, coming from Python, I already had a pretty firm understanding of closures and scopes, but I still really enjoyed the deep explanation as well as visualizations of JavaScript internals. Great work!

  • @RakeshSingh-vl2mz
    @RakeshSingh-vl2mz 2 месяца назад +1

    Awesome explanation Lydia 🔥

  • @musti-mm1
    @musti-mm1 2 месяца назад

    You are the only one that uploads a video purely for the thrill of actually teaching something new in your unique way and not one of those "new video every week" just for the sake of it. Please keep it this way.

  • @Kurigohan-and_k
    @Kurigohan-and_k 2 месяца назад

    Yeah! Another awesome video! 🔥🌈 I always feel a sense of joy whenever something new comes out on this channel ❤ Thank you Lydia!

  • @JoeBuza
    @JoeBuza 2 месяца назад

    Thorough and well structured. Thank you

  • @stio_studio
    @stio_studio 2 месяца назад +2

    This method could be a cool way to create classes without classes. Thanks for the idea :D

    • @edgeeffect
      @edgeeffect 2 месяца назад +1

      This was actually how classes were implemented back in prehistory (Algol). Some of us will say this is "the right way" to do OO in JS.

  • @FadingSuns-dn5hy
    @FadingSuns-dn5hy 2 месяца назад +1

    This is a legendary quality content!

  • @TechSpot56
    @TechSpot56 2 месяца назад +1

    Great Explaination, Keep these videos coming.

  • @frankdearr2772
    @frankdearr2772 2 месяца назад +1

    Great topic, thanks 👍

  • @pouryaalipanah3407
    @pouryaalipanah3407 19 дней назад

    amazing videos and explanations and visual examples . thanks thanks and many thanks , please go on

  • @starmechlx
    @starmechlx 2 месяца назад

    This is so dang good. I knew _how_ closures worked, but I never knew _why_ closures worked. I feel like if I got asked this in an interview and gave this explanation, it would maybe catch the interviewers off guard. :D

  • @TemuriKitoshvili
    @TemuriKitoshvili 2 месяца назад +1

    Your videos and explanations are best

  • @viktorpavlovych
    @viktorpavlovych 2 месяца назад

    Thank you so much, Lydia, really useful and clear explanation

  • @kevinschiener
    @kevinschiener 2 месяца назад

    Wrote about a related issue in React some weeks back. Great explainer from you; and I especially dig the consistent wording around environment record and execution context etc. I found it hard to keep track of those definitions when writing - intermingled them with scope and variable context. You did a much better job 👏

  • @sabermazoji-s7b
    @sabermazoji-s7b 2 месяца назад +1

    Great video! Please keep making videos like this :)

  • @DevMe-f5v
    @DevMe-f5v Месяц назад

    I won't skip ads for you, thanks a lot

  • @BilalAhmed-nx6sr
    @BilalAhmed-nx6sr 2 месяца назад

    Woah... a new video finally... can't believe JavaScript can be this easy to understand.

  • @parthjohar2273
    @parthjohar2273 2 месяца назад

    Great explanation with Great Visualization! Looking forward to seeing more content like this!

  • @soheil2759
    @soheil2759 2 месяца назад

    Thank you for your visualized videos They are so much helpful

  • @gizemavcs8599
    @gizemavcs8599 18 дней назад

    You're amazing!! These videos so helpful.

  • @subhajitdas2784
    @subhajitdas2784 2 месяца назад

    The explanation was so clear that I now completely understand what JS closures are. Additionally, I also got closure to why my ex broke up with me.

  • @grimplate
    @grimplate 28 дней назад

    Excellent explanation and the way u present phew! thanks for doing this for free....

  • @itsadira007
    @itsadira007 2 месяца назад

    Wow this is really amazing, I hope you keep making videos like this

  • @sanjeebpadhi8210
    @sanjeebpadhi8210 2 месяца назад

    Lydia great explanation & visual effect are amazing.

  • @alexrecuenco
    @alexrecuenco 21 день назад

    First of all, amazingly explained.
    But, second of all, I might be wrong, but iI believe all variables not used by closures get optimized away.
    So I don't think you need to worry too much about large temporary variables in your closure... unless you are programming for some really old engine.
    I notice this frequently when using debuggers and trying to use those variable names and noticing they don't exist anymore

  • @gerunkwon2598
    @gerunkwon2598 2 месяца назад +1

    Is it safe to say that closure variables are copies of the original variables at the times they were executed? Multiple sources keep telling me they're "captured", and NOT copied, but I have no idea what that even means.
    Anyways, you've made one of the best, if not the best, JS content on RUclips. You've managed to take important JS concepts and not only explain them super in depth, but also visualize them so well for a beginner like me. Please never stop creating!

    • @filipbystricky7301
      @filipbystricky7301 2 месяца назад

      "capture" is one of those vague terms so I understand the confusion!
      Another term people use is "closing", as in "it closes over the variables in the outer function", which is where "closure" comes from. But once again, that is a vague term that doesn't explain what's going on :)
      Basically a closure is an object that has a reference to the data in its surroundings (as Lydia explains, in JS this reference is called outerEnv, and its surroundings are the outer function's environment record). So to answer your question, no, the outer function's variables are not copied into the closure: instead, when the closure wants to access one of them, it does so using its outerEnv reference. You can verify this by creating multiple closures inside the same outer function:
      function outer() {
      let outerVar = 1;
      function increment() {
      outerVar++;
      }
      function log() {
      console.log(outerVar);
      }
      return {increment, log};
      }
      let {increment, log} = outer();
      increment();
      log(); // logs 2
      If the variables were copied, then "increment" and "log" would each have their own copy, so "log" would output 1 instead of 2.
      Hope this helps :)

  • @AbelAdane-s5h
    @AbelAdane-s5h 2 месяца назад

    Welcome back your explanation is great keep it up

  • @abdul140
    @abdul140 Месяц назад +2

    Hello ,can you make videos on these advance topics :
    1. Prototypal Inheritance
    2. Currying
    3. Throttling
    4. Debouncing
    5. CORS

  • @nikbivation
    @nikbivation 2 месяца назад

    very nice visualizations, and amazing explanations!

  • @varun-ns1nf
    @varun-ns1nf 2 месяца назад

    Wow great explanation. Please make a video on "this" key word in JavaScript

  • @gatogordo4131
    @gatogordo4131 Месяц назад

    Brutal! Perfect, now I got it

  • @abhijitez
    @abhijitez 2 месяца назад

    As usually, detailed breakdown on the internal working 💯

  • @petazeta76
    @petazeta76 2 месяца назад

    Goog!! Im looking forward to hear about iterators

  • @michaelharrington5860
    @michaelharrington5860 2 месяца назад +1

    The only YT videos I like before hitting play

    • @theavocoder
      @theavocoder  2 месяца назад +1

      ah thank you!! 🙏 but please don't be afraid to let me know if there are things you don't like, haha

  • @Sagarahuja-z5i
    @Sagarahuja-z5i 2 месяца назад

    after watching other's videos in 2x to save my time, it was pleasure watching your explaination in 0.75x.

  • @KlausKazlauskas
    @KlausKazlauskas Месяц назад

    Recently found your channel and your videos are amazing. Great thorough explanations assisted by those amazing visuals! What tools do you use to make them? The attention to detail is so big that I imagine it takes a very long time to make all look as tight and consistent as it is.

  • @manishshaw1002
    @manishshaw1002 2 месяца назад

    Waited for a long time to get the video!😮

  • @tahasin2321
    @tahasin2321 2 месяца назад

    You are great about explaining JavaScript ❤❤

  • @nguyenucan4746
    @nguyenucan4746 2 месяца назад

    Awesome works!

  • @fazzyakamello
    @fazzyakamello 2 месяца назад

    Thanks for sharing this video! It was really useful

  • @roskiboy
    @roskiboy 2 месяца назад +2

    Me gusta como presentas la información; es muy entendible aunque no entienda el inglés. Saludos.

  • @whiteandy
    @whiteandy 2 месяца назад

    Gold content. THANK YOU VERY MUCH

  • @babyfox205
    @babyfox205 24 дня назад

    this fantastic, ❤thank you so much you adorable angel of a person ❤ so much hard work and great explanation, please keep making new videos 🙏

  • @LiquidMamba
    @LiquidMamba 2 месяца назад

    Great video and absolutely interesting and easy to understand...BTW Can you make a whole JS tutorial from beginner to advanced? it would be so cool

  • @karansethia1037
    @karansethia1037 2 месяца назад

    This is insane🔥🔥 the visualization and explaination, also if youcreated this with keynote, just how many slides are in there😂

  • @vOnez212
    @vOnez212 2 месяца назад

    Awesome job! Keep it up. This is great content.

  • @sayeddileri3461
    @sayeddileri3461 2 месяца назад

    Been waiting on this one ❤️🙌

  • @MohammadJNajafi
    @MohammadJNajafi 2 месяца назад

    Thank you very much for the great content ❤

  • @HeyMr.OO7
    @HeyMr.OO7 2 месяца назад +1

    Pls make a JavaScript course or Typescript or any tutorial for that matter but pls do make one !! 💙

  • @Huzaifa_Hussain
    @Huzaifa_Hussain 6 часов назад

    we want more videos like this

  • @kartikkaushik4743
    @kartikkaushik4743 2 месяца назад

    Incredible share

  • @Vedarta
    @Vedarta Месяц назад

    My god, your videos are awesome!👏🏻👏🏻👏🏻

  • @wduandy
    @wduandy 2 месяца назад +1

    Nice explanation. What software you use for the animations?

  • @ShervanDev
    @ShervanDev 2 месяца назад

    Make more of these videos(js), thanks for your information

  • @cieranholmes
    @cieranholmes 2 месяца назад

    the GOAT has returned

  • @KobiBHat
    @KobiBHat 2 месяца назад +1

    Could you please explain how the V8 engine works in the Node.js runtime and also in the browser? Thanks a lot for your guidance!