0

In my pursuit of learning JS. I learned about IIFEs today. I understand that the main reason to use them is to obtain data privacy. Also, it helps prevent name collision and that it cannot be accessed outside of its function? So the question I have is the following: You only use IIFEs in a local scope, but not in a global scope? Lets say I want to create an onClick function for a button that does only one in the entire app. Would an IIFE be a good case of using it here?

Any explanations are welcome and thank you.

csb00
  • 1,091
  • 2
  • 18
  • 36
  • 1
    Does this answer your question? [Benefit of Immediately-invoked function expression (IIFE) over a normal function](https://stackoverflow.com/questions/37021349/benefit-of-immediately-invoked-function-expression-iife-over-a-normal-function) – khan Mar 17 '20 at 01:22
  • 1
    This question might generate to long of a response. Could you be more specific and concise? Regarding IIFEs, you can use them anywhere. – Mike Mar 17 '20 at 01:22
  • It's just a tool, and not so impotent compared to other things like async or view framework, just use what you like as long as it doesn;t bring trouble. when it does, you know the tool and you konw how to solve it – Josh Lin Mar 17 '20 at 01:29

0 Answers0