From the course: Learning Functional Programming with JavaScript ES6+
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Understanding closure - JavaScript Tutorial
From the course: Learning Functional Programming with JavaScript ES6+
Understanding closure
- [Instructor] All right, so previously we talked about how it's possible to return functions from other functions in JavaScript. And this concept actually leads us to another very important concept in functional programming, and this is something called closure. Now, basically, closure means that when we return a function from another function as we've done here, oops, let me try that again. There we go. The function that we return still has access to the scope that it was returned from. So that probably doesn't mean a whole lot to you yet. So let me show you an example that will demonstrate closure. First of all, I'm going to create a new file here, which we'll call something like closure.js And inside here what we're going to do is we're going to create a function that returns a function. We'll call this createPrinter again. But the difference here is that this function is going to have a variable inside of it called something like my favorite number, and we'll make that 42. All…
Contents
-
-
-
-
JavaScript arrow function syntax9m 15s
-
(Locked)
Using functions as data8m 52s
-
(Locked)
Creating arrays of functions6m 31s
-
(Locked)
Passing functions as arguments7m 47s
-
(Locked)
Returning functions10m 29s
-
(Locked)
Understanding closure8m
-
(Locked)
Higher-order functions8m 1s
-
(Locked)
Tour of CoderPad1m 29s
-
(Locked)
Solution: More higher-order functions2m 34s
-
-
-
-
-