Wow, that was needlessly complicated and (IMO) incorrect.<p>Any function that has free variables that are not global variables is a closure. Another way to think about it: any function that cannot be implemented in C is a closure.<p>So, in these examples, the inner functions are closures, the outer ones are not, but <i>only</i> because the outer ones are used in a global scope. If you enclosed everything in another function, then also the outer functions would be closures.
Chapter 3 in "Structure and Interpretation of Computer Programs" (SICP) explains the environment model to evaluate scheme. That's exactly what you need to understand javascript closures.<p>Only read the 3.2 part, it's not long: <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-21.html#%_sec_3.2" rel="nofollow">http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-21.html...</a>
This question comes up so often both in IRC support channels and on SO that I don't understand why this wasn't closed as a duplicate.<p>The accepted answer also overcomplicates what could be a very simple answer.<p>In a quick Google, I found this. Asked in '08, not '12: <a href="http://stackoverflow.com/questions/111102/how-do-javascript-closures-work" rel="nofollow">http://stackoverflow.com/questions/111102/how-do-javascript-...</a>
The second answer states it best: "They all use closure(even in the 1st example)."<p>If you're accessing a local variable from a different function scope than it was created in then you are using a closure - there is nothing special about how it was defined, this is the only distinction.