Self Invocation of a function is a way in which you can protect your Global Scope by not exposing the variable to the Global Scope. This helps to prevent your code and protect it from accessing the Global Environment.

The way in which you can enable Self Invocation is as follows.

Self Invocation with Arguments

Its possible to pass Arguments to the above code in order to protect the global scope as well as invoke it automatically. You don’t need to invoke this piece of code since it can automatically invoke itself. Now let’s see how we can have a variable being passed to this function.

Check out all the other posts on JavaScript Essentials to get a Grasp of these JavaScript Utilities.


Also published on Medium.

Join our 2500+ fellow readers

Join our 2500+ fellow readers

Joining our mailing list will for sure keep you at the top of Web Development Ecosystem. Connect with us and also other fellow developers.

You have Successfully Subscribed!

Pin It on Pinterest

Share This