JavaScript Closures
Learn about JavaScript closures.
We'll cover the following
By the end of this lesson, we’ll be able to understand how closures work.
Closures
JavaScript functions have lexical scopes. The accessibility of the variable to a function depends on where that variable is declared within the code, hence the term “lexical.”
A function that’s nested inside another function has access to variables declared in its local scope, the outer function’s scope, and the global scope. The nested function is called a closure.
Let’s see what we get after running the provided code:
Get hands-on with 1200+ tech skills courses.