[jQuery] javascript variable scope

2009-12-04 Thread cmonahan
This surprised me. I made the scenario as simple as possible. http://jsbin.com/eyopo3/edit You can see in function g() I change the value of the variable i after having used it. That may seem like a useless thing to do, but in the production code I was working on, i was a loop iterator. --

Re: [jQuery] javascript variable scope

2009-12-04 Thread Richard D. Worth
Cool, huh? This is one of the beauties and real powers of the JavaScript language. It's called a closure: https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Working_with_Closures - Richard On Fri, Dec 4, 2009 at 6:46 PM, cmonahan cmona...@yahoo.com wrote: This surprised me. I made