This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var array = ["zero","first","second","third","fourth","fifth"]; | |
var closures = []; | |
for(var i=0, l=array.length; i<l; i++){ | |
closures.push(function(){return array[i]}); | |
} | |
closures[3](); | |
// Expected "third", but actually returns 'undefined', | |
// because js did not create a separate scope for the "for" block |