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.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Pin It on Pinterest

Share This