Member-only story
An Introduction to IIFEs for Beginners
What are IIFEs? IIFEs or Immediately Invoked Function Expressions are functions that get invoked the moment they are defined.

Immediately Invoked Function Expression, you are using them without knowing
IIFE are what you call Immediately Invoked Function Expressions, is a function that gets invoked the moment is defined. It’s also a pattern known as the Self-Executing Anonymous Function. A basic IIFE looks like
(function (){
console.log("You Don't Invoke Me, I Invoke Me");
})()
The moment the function is read it gets invoked:
At a glance, it looks simple, and tbh it is. Where things get a little complicated is deciding where to use them. So let’s look at some examples and use cases to understand how they work, and the final result might be a little more surprising than you would expect.
Let’s keep the Global Namespace clean
With modern JavaScript applications, we are injecting a lot of dependencies, and some of them are either dependencies that get defined in the global/window object. But what if we define a global variable that overrides a variable, used by another dependency, things will break. There is a reason why…