DEV Community


Discussion on: Explain IIFE(Immediately Invoke Function Expression) Like I'm Five

shiling profile image
Shi Ling


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.



    // some code you just want to run only once, e.g. setup Vue js.
    var app = new Vue({
        el: "#main",
        //... more stuff
latheresienne profile image
Latheresienne Author

Thanks for the explanation😃