I read so much about one of the uses of an iife is to help in namespace conflict resolution and how it makes it difficult to accidentally affect the global object & pollute the global scope. And how it leads to safer code.
My question is, all that already happens in a function that is not immediately invoked. Do we specifically need an iife to get those benefits? How does using IIFE & thus hiding and creating a separate environment, is any different from a regular function? In an iife, the variables are local (thus they do not pollute global scope) but so are they in non-iife functions.
Am I right in saying that iife do not help in variable name collision, but help in function name collision? Variables in even normal non-iife functions are locally scoped and not colliding with global variables, isn't it?
So, in a nutshell, when they talk about polluting the global scope specifically w.r.t. an iife, they are talking about not polluting the scope w.r.t. method names and not variable names ?