IIFE
Ask friend for the WIFI password, use it immediately, forget about the password afterward.
Normal Function
Ask friend for the WIFI password, writes it on a piece of paper, paste on the wall, everyone knows it.
What's the point of IIFE?
The IIFE is a javascript design pattern invented in the days before modules was introduced in ES6, and people wanted to run a piece of code only once, like a setup code, without polluting the global namespace.
e.g.
(function(){// some code you just want to run only once, e.g. setup Vue js.varapp=newVue({el:"#main",//... more stuff})})()
Analogy:
IIFE
Ask friend for the WIFI password, use it immediately, forget about the password afterward.
Normal Function
Ask friend for the WIFI password, writes it on a piece of paper, paste on the wall, everyone knows it.
What's the point of IIFE?
The IIFE is a javascript design pattern invented in the days before modules was introduced in ES6, and people wanted to run a piece of code only once, like a setup code, without polluting the global namespace.
e.g.
Thanks for the explanation😃