A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the local environment). In other words, a closure gives you access to an outer function’s scope from an inner function.
JavaScript variables can belong to the local or global scope.
Global variables can be made local (private) with closures.
Global Variables
A function can access all variables defined inside the function,
function myFunction() {let a = 4;return a * a;}
But a function can also access variables defined outside the function,
let a = 4;function myFunction() {return a * a;}
In JavaScript, closures are created every time a function is created, at function creation time.
function makeFunc() {const name = "C-Sharpcorner";function displayName() {console.log(name);}return displayName;}const myFunc = makeFunc();myFunc();

