What is a Self-Invoking function?
A self-invoking function is called immediately after definition. For example look at the following codes:
Why do you need a self-invoking function?
A self-invoking function is an anonymous function and thus all the variables defined inside it are scoped and hence you keep the namespace polution out of it.