From the course: Mastering Web Developer Interview Code

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Create a practical example of closures

Create a practical example of closures

From the course: Mastering Web Developer Interview Code

Create a practical example of closures

- [Instructor] Closures are a super common concept in JavaScript. If you've spent some time with the language, you're probably already using them, even if you don't know that you are. It's one of those concepts that makes a good but tricky interview question. So let's take a look at a definition and then take some time for coding practice. Before we can talk about closures, we need to review how JavaScript Scope works. Scope refers to the area within a computer program where a variable is available. Variables are created and exist within different regions. They're essentially bound to certain regions within your application. Now JavaScript uses something called lexical scoping. Lexical scope describes how variable scopes are determined when there is a function inside another function. Using lexical scope, the inner function will have access to variables in the parent function. And this is essentially what a closure is.…

Contents