self executing function jquery vs javascript difference

后端 未结 9 813
长发绾君心
长发绾君心 2020-12-02 19:59

What are the difference among -

First :-

(function () {

    var Book = \'hello\';

}());

Second:-

9条回答
  •  长情又很酷
    2020-12-02 20:41

    Immediately-invoked function expressions (IIFE) is one of the core JavaScript features. Its main aim is not to clutter the namespaces with disposable functions and variables.

    if you use a variable or a function only once, you don't need to make it available for the rest of the code (therefore you make a private access, for example). In case of functions, you may just let them be anonymous, just like the following:

    (function(){
      console.log("Hello symfony world!");
    }());
    

    Please check with this link

    Furthermore here is a useful explanatory video in less than 7 minutes

提交回复
热议问题