A closure is a function having access to the parent scope, even after the parent function has closed.
A closure is a function that returns a function. The function that is returned (the inner function) is created inside the called function (the outer) so – due to the scoping rules we’ve seen – the inner has access to the variables and arguments of the outer.
Merely accessing a variable outside of the immediate scope (no return statement is necessary) will create something called a closure. Mozilla Development Network(MDN) gives a great definition:
“A closure is a special kind of object that combines two things: a function, and the environment in which that function was created. The environment consists of any local variables that were in-scope at the time that the closure was created.”
1) Most useful for events and callbacks
3) Used to create function factories