What is a closure? In this Javascript Tutorial, we’re going to be learning about closures – our 3rd most misunderstood concept of Javascript.
Watch the full playlist:
Hopefully, we’re going to break it down enough to make it simple to understand for newbies and intermediate coders alike.
Javascript closures are really not that complex of an idea.
The textbook definition of a closure is a function that retains state and scope after it executes. Basically put, when the function’s done, a callback might need to access the variables inside later…so Javascript remembers those variables. That remembering of the variables is called a closure.
Original source
32 responses to “Javascript Closures Tutorial – What makes Javascript Weird…and Awesome Pt 3”
You got yourself a new subscriber!!
BTW i wanted to learn back-end programming which one should I learn PHP or node.JS??
So damn good explanation. Thanks, mate.
Do you have any complete video for downloading option?
where JS))) without jQuery please
Such an awesome video. Very informative. Thanks a lot. But where is the part for scope and context? I cannot find it. Can somebody give me the link?
Hi, I'm slowly moving over from AS3 to JS. I'm wondering if (in this example) a were an object or an array, would you have to nullify the object or array before it gets picked up by garbage collection? For example, a = ["val1", "val2"]. (then before closure) a = []. AS3 had an odd tendency to keep certain things in memory – is this the same with JS?
wow. i wish jason from codeschool explained it like this. cant believe i still did not know what a closure was. he really explained it in depth though, i wonder why i couldnt comprehend it from him. is this a simple way of explaining it? are there more complicated expressions of closures? whats a good place to read further on closures? thanks man.
Literally the best explanation on the entire internet on closures! Much appreciated guys. Thank you
I'm amazed by the quality of the content you're putting up here! There's a ton of JS material out there but the fact that this is about the 20th of your videos that I'm watching speaks for itself.
Just to help fellow learners along, a lot of these JS concepts are super weird when you come from more classical object-oriented languages like Java (as it was the case for me). A really good summary of essential JS concepts with respect to functional programming can be found here: http://jrsinclair.com/articles/2016/gentle-introduction-to-functional-javascript-intro/
Thanks for posting, this is one of the best explanations of closers that i have come upon. Thumbs up for sure!
Alrite, finally get it, thanks
Will, Where is the memory that is storing the javascript code and all the closures? Is the browser taking a small memory block out of your computer to store it every time you load the page? Just wanted to know.
This has always been a mystery to me until you explained in a very clear manner. Now I can "see" what's going on with my code. Thanks.
thx dude , 4:07 hehehe so funny
Sorry if I didn't catch it, but just to confirm, the thing that is called the closure here is the variable 'a'. Is that correct? I've seen the word closure used as an adjective instead of a noun before so I'm a bit confused
Good tuto but jQuery is too big and introduces weird syntax, you shouldn't teach vanilla js concepts with it.
Best description on closures that I have seen.
I wish there were less of these tutorials in JQuery. Vanilla JS is the way to go for learning. Nobody should learn IN JQuery.
Thanks, that was one of the clearest and least complicated explanations I've seen about closure.
great tutorial man. by the way, what mac do you have?
It would be awesome if you can explain how to use IIFE with closures. Lets say if an loop you want to remember and return each looped value instead of the last value. Until this day, I am still confusing about it.
Btw, I just want to say your tutorials are the best so far. Much better than many large website's vague tutorial
Once again… thank you 😀
Yours tutorials r awesome (y)
Is there any list of topics u have covered,, as sometimes its very tough to find ur video tutorial in a sequential manner.
how i can make my website public?
I was almost wondering where are the rest two videos, then I realize you made this one only a week ago. Thanks for making this series. You can explain things so clearly and so effectively. It's incredibly hard to find a good video like this!
I think people might want a release schedule for your tutorials 🙂
I agree with Sergey, plus more into the ExecutionContext – Runtime Environment.
I really enjoy your tutorials! Waiting for next video in series! Thanks you for this!
Nice videos! Waiting for the next coming 🙂
Waiting for next video 🙂
ALready waiting for the rest. And I think you need to add another one JS Objects. There are many ways to create an object and how and why you can initialize function as an object with "new" state.
which color scheme you use?
Thanks for the series, this sort of short and quick video style is great!