How Closures Work in JavaScript: An Overview

added by JavaScript Kicks
8/14/2018 4:50:22 AM


Closures are a very powerful yet underused feature unique to of JavaScript (and other ECMAScript languages). They essentially provide your code with private variables that other scripts can't access. This is accomplished by exploiting three interesting features (or "quirks") of JavaScript: JavaScript is executed in-place Functions can be self-executed Variables inside a function exist after a function completes Let's start by examining some JavaScript that doesn't use closures.