IIFE stands for Immediately Invoked Function Expression. An anoymouns function that will be invoked soon after its declaration.
1 | (() => { |
Though it looks weird or beautiful (to me ^_^), there are great benefits that come along with this IIFE approach.
Modularity
We can group our components or modules in a IIFE so that namespace conflicts reduced almost to none.
Scoping
We can declare our local functions and variables without worrying about polluting global scope or namespace conflicts.
1 | (() => { |
Extras:
- Typescript transpiles into IIFE javascript functions.
- For AngularJS developers, this is one of most streesed guidelines.