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.