Javascript Immediately Invoked Function Expression IIFE – Tutorial




What is IIFE and how to use it (with code example) ? Javascript iife pattern .

Javascript iife namespace
WHat is Function Expression
self-executing anonymous function
self-invoked anonymous function
JS IIFE example
techsith

Original source


43 responses to “Javascript Immediately Invoked Function Expression IIFE – Tutorial”

  1. Wow so much depth in your tutorials. May I ask what kind of courses you did to learn all of this? I'm hoping to do a course that will give me a deep understanding of developing for the web and applications, hopefully an MSc, could you please recommend any courses?

  2. The first impression that I had of IIFE was that defining the expression itself would execute the same. So, with reference to your example, the functions defined inside the object being returned would execute. But, that does not seem to be the case. I could not get my hold into the idea behind calling it "immediately invoked". Though I could understand that idea of limiting the lookup to within the function scope by kind of porting the parameter passed. Would appreciate some pointers.

  3. The purpose of IIFE is not to pollute the global namespace. In this example, I see the function expression name 'counter' is still registered to the global namespace.
    If someone unknowingly registers the variable named 'counter' in the global namespace (window object) then the above function expression name i.e. 'counter' will be overwritten. How to solve this kind of problems even though we are using IIFE here?

Leave a Reply