Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 44
    Point 1. How? Point 2. That's from a completely different best-practice. Point 3. What function doesn't? 4,5,6,7. Relevance? 8. Well, 1/8 ain't bad I guess. Commented Aug 18, 2012 at 0:19
  • 3
    Seven years late but, for point 1. it doesn't reduce code at all, in fact it adds a minimum of two lines of code in creating the function. Commented Mar 3, 2017 at 15:52
  • 2
    only point here is "It provides a closure which prevents naming conflicts", every other point is rewording of this or false. maybe you can simplify your answer? Commented Dec 18, 2018 at 19:37
  • The statement "It’s about defining and executing a function all at once." is wrong. Javascript code is first parsed in its entirety, then executed. Code can't be selectively executed before other code has been parsed (i.e. functions and variables defined). IIFEs allow running code in function scope that might otherwise have been global, and to create other values (objects, functions, etc.) that might be available to code outside the function that created them through closures. Commented Jul 14, 2024 at 9:58