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 book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

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