Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!

A closure is an inner function that has access to the outer scope, even after the outer scope has executed.

Scope

Scope defines the lifetime and visibility of a variable.

Every time we create a function or a block {} , we create a new scope.

Variables declared with var have only function scope. Variables declared with let and const can have function and block scope.

A closure is a inner function. It has access to variables from the outer scopes.

Variables used by the closure function live as long as the closure lives.

Closures make it easy to work with async tasks like timers, events, AJAX calls.

Closures create encapsulation.

Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!

For more on applying functional programming techniques in React take a look at Functional React.

Read more on Vue and Vuex in A Quick Introduction to Vue.js Components.

Learn how to apply the Principles of Design Patterns.

You can find me on Medium and Twitter.