To my limited knowledge what you explained is lexical scope which is part of closure but closure is little more complex than that, maybe a reference of Dave Gray's video will help a little
@JamesQQuick2 жыл бұрын
I think the addition to lexical scope here is the fact that the function isn’t called immediately. It’s called at some later time and still has access to the variables. Lexical scope would more specifically refer to the case where you are accessing the data right then (not at a later point) I believe.
@rafalka70842 жыл бұрын
The best usage of closures is to create private variables I think.
@chetanjain46162 жыл бұрын
@@rafalka7084 encapsulation would be the better term but yeah
@invictuz48032 жыл бұрын
Yes you're right, you also need to understand the concept of the call stack and function execution contexts and how these two are *determined dynamically* by how the function is *called* at runtime, as opposed to how lexical scope is *determined statically* by where the function is *defined* (in the code) at compile time. This is important as you'll often see popular articles mix up the terms, execution context and scope, which will get really confusing as you try to understand how it all works under the hood of the JavaScript engine/interpreter.
@terjes642 жыл бұрын
Thought it was more about if you keep a reference to a function, and that function has a reference to something that is out of scope of the first reference, the second reference is available as long as the first reference still exists?
@JamesQQuick2 жыл бұрын
Yeah I mean that's basically the same thing here. Any time something is referenced inside of a function that isn't called until later, the fact that it keeps the reference is it.
@Paul-wy6tn2 жыл бұрын
Straight to the point, cheers mate
@chukwuemekaorji93312 жыл бұрын
The video was amazing thank you so much. Plus, I really love your theme and your font, I do love to know and use it thank you so much.
@harleyspeedthrust40132 жыл бұрын
I use that pattern all the time. I have a web app which uses handlebars for the frontend, and there are many pages where there's a list of items and I need to add event listeners to each one - so this comes in handy
@programming30432 жыл бұрын
Can any one tell what theme is he using? Does he share his settings.json?
@sabinadhikari6092 жыл бұрын
Hey James, what theme, font are you using? Also, did you do any changes in the default theme you used? Thanks James, keep up the good work. Hoping to watch your next video soon
@kemekenneth2 жыл бұрын
I was scrolling the comment to see who has asked the theme question. It's beautiful. James, I need it too. Thanks for your videos.
@AlejandroLZuvic2 жыл бұрын
I use the font Cascadia Code. I’m using VS Code with the Cobalt 2 Theme. It's in the Advent Page he mentioned, worth checking.
@jdavis25812 жыл бұрын
I think I found it - Midnight Synth
@devxlk2 жыл бұрын
Great Video ❤❤❤
@Spartacus692 жыл бұрын
But why does "i" increment?
@zotoavinaandriamanamihaga66612 жыл бұрын
what is this vs code theme
@jdavis25812 жыл бұрын
Does anyone know what VS Code theme this is? I don’t believe this is the regular Cobalt 2 that he normally uses.
@jdavis25812 жыл бұрын
Found it - Midnight Synth
@JimKernix2 жыл бұрын
I don't understand how the i parameter in the forEach was actually logged out since you didn't define it in the addEventListener.
@thewiscokid812 жыл бұрын
Great video and explanation.
@anuphaldar31922 жыл бұрын
Your videos are awesome as your vs code theme, can you share the theme plz🙈
@jsayubi2 жыл бұрын
Love your videos, Thanks so much ❤
@eder81702 жыл бұрын
That was solid 5 minutes.. thank u sir
@Luc-dcx2 жыл бұрын
Thank you James.
@ste-fa-no2 жыл бұрын
Simple 👏Worth noting that if you instanciate a "const n = Math.random()" each button will have its own different "n", but always the same "n" for every click on a singular button
@JamesQQuick2 жыл бұрын
If it’s inside of the for each yes you are correct!
@MirkoMancini2 жыл бұрын
Thanks, great video!
@snehitlal7712 жыл бұрын
That's it !!...loved it !
@JamesQQuick2 жыл бұрын
Glad you liked it!
@bmehder2 жыл бұрын
I think this is one of the best explanations of closures I have come across.
@JamesQQuick2 жыл бұрын
WOw, so glad to hear that!
@yashraj65652 жыл бұрын
This is awesome 💚
@JamesQQuick2 жыл бұрын
Glad you enjoyed it!
@chriscancode52022 жыл бұрын
I've been using closures for years without even knowing that's what they were. lol.
@kamertonaudiophileplayer8472 жыл бұрын
I use closures but not very frequent. Generally, your guide is good. Keep going.
@bikabas2 жыл бұрын
Vs code theme please ...
@AlejandroLZuvic2 жыл бұрын
I use the font Cascadia Code. I’m using VS Code with the Cobalt 2 Theme. It's in the Advent Page
@231-o5m2 жыл бұрын
good
@dmytronice13372 жыл бұрын
sry, but is it fullhd or no?
@deepakishere-e1d2 жыл бұрын
thanks
@lexsemenenko2 жыл бұрын
I have a vague understanding of closures, but this example does not explain closures at all in a way it is commonly used.
@JamesQQuick2 жыл бұрын
Hmm anything you’d like to add or clarify?
@lexsemenenko2 жыл бұрын
@@JamesQQuick In a foreach loop, in each iteration, the index is accessed from the inner function simply by the rules of scope. Function scope - meaning everything inside has access to it. Closure: an inner function always has access to the variables and parameters of its outer function (Yes), and the mind blowing fact is when it's in a situation after the outer function has already returned. But the values are remembered to be accessed after the outer fn return. The magic point of it. ) So the idea of private variables comes from this magic feature. I've seen examples of it where it was difficult to wrap my mind around it. Sorry for the confusion. It's true what the video described. But just there are deeper meanings I believe.
@JamesQQuick2 жыл бұрын
@@lexsemenenko I appreciate the detailed response. Agreed there are deeper implications and use cases than what's covered in the quick video
@jowniemand25142 жыл бұрын
your explanation is a bit cryptic. I use closures a lot and I can somehow figure out what you are trying to say, but your tut lacks enough explanation to be able to grasp it the way it is explained. Perhaps you are using it in a way I have never used it, so pardon my ignorance in that case, but I am still puzzled.
@danvillewilks95492 жыл бұрын
That was sooooo simple wow thanks a lot
@JamesQQuick2 жыл бұрын
Glad that helped!!
@ming39572 жыл бұрын
@longb19132 жыл бұрын
3:13 wtf is a callback listener, try use simple language in a tutorial