JavaScript variables can belong to the local or global scope.
Private variables can be made possible with closures.
A closure is an inner function that has access to the outer (enclosing) function’s variables—scope chain. The closure has three scope chains: it has access to its own scope (variables defined between its curly brackets), it has access to the outer function’s variables, and it has access to the global variables.
Example: -
var add = (function () {
var count= 0;
return function () {return count+= 1;}
})();
add();
add();
add();
add();
// the count is now 4
A closure is a function having access to the parent scope, even after the parent function has closed.
In other words,
Closures are functions 'remember' the environment in which they were created.