self executing function jquery vs javascript difference

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

What are the difference among -

First :-

(function () {

    var Book = \'hello\';

}());

Second:-

9条回答
  •  萌比男神i
    2020-12-02 20:34

    All three examples are Immediately Invoked Function Expressions (IIFE).

    The only difference is that in the third example jQuery is being passed in as a variable allowing you to use it within the IIFE using its dollar naming convention. e.g.

    (function ($) {
      var Book = 'hello';
      $('#bookelement').html(Book);
    })(jQuery);
    

提交回复
热议问题