A closure gives you access to an outer function’s scope from an inner function
//example
function init() {
var name = 'Mozilla'; // name is a local variable created by init
function displayName() { // displayName() is the inner function, a closure
alert(name); // use variable declared in the parent function
}
displayName();
}
init();
A combination of a function object and a scope (a set of variable bindings)
in which the function's variables are resolved is called a closure.
Callbacks are functions that are passed into another function as an argument.
Closures are functions that are nested in other functions, and it's often used to avoid scope clash
with other parts of a JavaScript program