In this Learnable video you’ll learn about variable scope in JavaScript. How, when, and where you declare a variable dictates how you can access that variable later in your code. We’ll also see how understanding variable scope leads on to the extremely powerful concept of closures.

Tags: closures, learnable, scope

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.

  • Ricardo Matias

    Kudos for the tutorial! I just didn’t get one thing, why did you create the function generateClickHandler ? Couldn’t you just have done that with clickHandler(i) ?

    • Knight Yoshi

      Yes, it would be possible to pass an argument to clickHandler(arg) instead of wrapping it in another function, but I think, I could be wrong, that it was done this way to show function scope.

  • DJ

    I would love to watch but I can’t get the video to play at all. (and I paused any plugins that would block it).

  • OphelieLechat
    • DJ

      Yeah. I ripped the URL from the source too. No go. Must be one of my plugins blocking it but since I have no problem with videos from “normal?” hosting sites I really have no inclination to start wasting time figuring it out.

      Thanks for the reply though.

  • Mohd. Mahabubul ALam

    JavaScript is a powerful language, but it does have its… wrinkles.
    Variable scopes and closures certainly fit into that category. Often
    asking the same questions in different places can get you very different
    answers. Daniel walks you through some examples and explains why it all
    makes sense. Mostly.

Special Offer
Free course!

Git into it! Bonus course Introduction to Git is yours when you take up a free 14 day SitePoint Premium trial.