Understanding Variable Scope & Closures Without Losing your Mind

Daniel Zabinskas

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.

Free JavaScript: Novice to Ninja Sample

Get a free 32-page chapter of JavaScript: Novice to Ninja and receive updates on exclusive offers from SitePoint.

  • 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) ?

  • OphelieLechat
  • 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.