closure

A collection of 2 post

Why wrapping source file in an immediately invoked function?

What is the reason for wrapping the entire contents of a JavaScript source file in a function that is immediately invoked? Answer This technique is very common in JavaScript libraries. It creates a closure around the entire contents of the file which creates a private namespace and thereby helps…

What is a closure?

What is a closure? Can you give a useful example of one? Answer A closure is a function defined inside another function and has access to its lexical scope even when it is executing outside its lexical scope. The closure has access to variables in three scopes: Variables declared in its own scope…