课程: Mastering Web Developer Interview Code
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
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.…