Step by step understanding JavaScript IIFE ( Immediately invoked function expression)

Поделиться
HTML-код
  • Опубликовано: 12 дек 2016
  • For more such videos visit www.questpond.com
    For more such videos subscribe ruclips.net/user/questpondvide...
    See our other Step by Step video series below :-
    Learn C# Step by Step goo.gl/FNlqn3
    Learn Design Pattern Step by Step:- goo.gl/eJdn0m
    Learn Angular tutorial step by step tinyurl.com/ycd9j895
    Learn MVC Core step by step :- tinyurl.com/y9jt3wkv
    Learn Azure Step by Step :- tinyurl.com/y6fmrech
    Learn SharePoint Step by Step in 8 hours:- goo.gl/XQKHeP
    Python Tutorial for Beginners:- • Python Tutorial for Be...
    Learn Data Science in 1 hour :- tinyurl.com/y5o7qbau
    Learn Power BI Step by Step:- tinyurl.com/y6thhkxw
    Learn MSBI Step by Step in 32 hours:- goo.gl/TTpFZN
    Learn SQL Server Step by Step tinyurl.com/ja4zmwu
    Learn Tableau step by step :- tinyurl.com/kh6ojyo
    In this video we will try to understand why we need JavaScript IIFE ( Immediately invoked function expression).

Комментарии • 27

  • @dnfvideo
    @dnfvideo  2 года назад

    30 Important C# Interview Questions : ruclips.net/video/BKynEBPqiIM/видео.html
    25 Important ASP.NET Interview Questions : ruclips.net/video/pXmMdmJUC0g/видео.html
    25 Angular Interview Questions : ruclips.net/video/-jeoyDJDsSM/видео.html
    20+ SQL Server Interview Questions : ruclips.net/video/SEdAF8mSKS4/видео.html
    5 MSBI Interview Questions : ruclips.net/video/5E815aXAwYQ/видео.html

  • @Teaktrades
    @Teaktrades 2 года назад

    this is the best explanation on both youtube and the internet about this concept. thanks so much for sharing this knowledge.

  • @srinivasaraoyp3640
    @srinivasaraoyp3640 2 года назад

    Very interesting topic in javascript. Thank you.

  • @farooqawan693
    @farooqawan693 6 лет назад +1

    Thank you for your teachings and advises.

  • @albertofabbri1543
    @albertofabbri1543 4 года назад

    Very clear video, thanks.

  • @gagangupta1255
    @gagangupta1255 4 года назад

    Very well explained - with real example.

  • @blastingsound22
    @blastingsound22 5 лет назад

    I did not understand what polluting the global meant . Now i do ! Thank you

  • @shakib_04
    @shakib_04 2 года назад

    quality video and explanation

  • @uche8961
    @uche8961 5 лет назад

    I used to wonder what polluting the global variable actually meant, now i understand. Thanks

  • @HashtagObi
    @HashtagObi 3 года назад

    thank you!!

  • @mdrohimsikder7669
    @mdrohimsikder7669 6 лет назад

    nice and thanks

  • @bhuvanatn
    @bhuvanatn 6 лет назад

    GOOD One

  • @dylanm7638
    @dylanm7638 2 года назад

    thanks

  • @jaydeepkasture8483
    @jaydeepkasture8483 3 года назад

    after you wrap the global variable into the anonymous function is it still the global variable?

  • @amitsunnysingh
    @amitsunnysingh 4 года назад +2

    I can happily say that no one knows the advantage of IIFE functions, just making stories

  • @balus143
    @balus143 7 лет назад

    Hi Shiv, So can't we use anymore iffy variables as a global variables ...? since we are unable to access the global variable (I.e. counter) inside of the function, then any ways to access a variable inside of the iffy block..?
    thanks
    Satya

    • @dnfvideo
      @dnfvideo  7 лет назад

      Hello Satya sir,
      The variables created inside IIFY will not be public he can still access public variables.

    • @umeshchauhan3223
      @umeshchauhan3223 4 года назад

      Hi Satya, the counter variable inside IIFE can be used via a public return function which can be defined in IIFE and it should return the counter variable. This is possible because of closure.

  • @stevedoetsch
    @stevedoetsch 3 года назад

    But doesn't the IIFE just get dumped from memory immediately after execution? So what good is it in this example?

  • @shatakhian
    @shatakhian 7 лет назад +2

    Instead of this complicated code we can just rename top "counter" variable to topCounter for example. It will be much simplier then IIFE.

    • @questpondvideos
      @questpondvideos 7 лет назад +1

      In projects of huge magnitude the components ( functions) are created by some on else and page by some one else. You never know with lot of global variables you are sitting on a ticking bomb.

  • @HimalayaGarg
    @HimalayaGarg 6 лет назад +1

    It is no more a global variable. Something wrong?

  • @atulmishra8753
    @atulmishra8753 4 года назад +1

    if you are using counter variable inside SomeFun() , then automatically then outer counter variable becomes irrelevant since the function will use its own counter variable so I am not sure if your example justify IIFE

    • @umeshchauhan3223
      @umeshchauhan3223 4 года назад

      The outer counter variable does not become irrelevant because without the IIFE, counter variable will be a global variable and all the other functions will use it as it is defined in global scope.

    • @RamSharma-yl6ur
      @RamSharma-yl6ur 4 года назад

      @@umeshchauhan3223
      var counter = 10;
      function oldFunction(){
      var counter = 50;
      console.log('counter inside oldFunction', counter);
      }
      oldFunction();
      console.log('counter outside oldFunction', counter);
      This video no longer make any sense and has not described IIFE. To read about IIFE visit benalman.com/news/2010/11/immediately-invoked-function-expression/

  • @RamSharma-yl6ur
    @RamSharma-yl6ur 4 года назад

    This video no longer make any sense and has not described IIFE.
    var counter = 10;
    function oldFunction(){
    var counter = 50;
    console.log('counter inside oldFunction', counter);
    // Prints 50
    }
    oldFunction();
    // Prints 10
    console.log('counter outside oldFunction', counter);
    To read about IIFE visit benalman.com/news/2010/11/immediately-invoked-function-expression/