From the course: Learning Functional Programming with JavaScript ES6+

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Closure

Closure - JavaScript Tutorial

From the course: Learning Functional Programming with JavaScript ES6+

Start my 1-month free trial

Closure

- [Instructor] In a previous video we talked about how in java script, it's possible to return functions from other functions. And saw some possible applications of doing this in our code base. Returning functions from other functions leads us to another very important concept in java script. And this is something called closure. So what is closure exactly? Well basically, closure means that when we define a function that returns another function, the function that we returned still has access to the internally scope of the function that returned it. In this case, the function that we returned still has access to the constant x. Even after we return it. To see what I mean a little better, let's code out an example that demonstrates the closure. First let's create a function called createPrinter. Const, createPrinter. And this function won't take any arguments. And for illustrative purposes, let's make a function body with more that one line using the brackets. So inside this function…

Contents