What's going on? In Perl, $i is scoped to the `for` block. Essentially, each time through the loop, a new variable is created, so the generated closures all refer to different $is. In Javascript, `i` is scoped to the `for` loop's containing function. Each of the generated closures refer to the same `i`. Which means that, to get the same effect as the perl code, you must write: