Are you staring a pile of JavaScript, wondering why anyone would use that pesky "var" keyword? Or perhaps your looking at a series of nested functions that seem to share variables, but you can't figure out how. And why is that function wrapped in parenthesis, with a bunch of vars in it?
Join me as I explore and explain the basics of managing the scope of variables in JavaScript. We'll work with with global and local variables, immediate functions, JavaScript modules, constructor functions, objects instances, and more. Along the way, we'll also look at a number of common JavaScript patterns that help us take advantage of scoping.
I also have a few blog posts related to variable scope in JavaScript: