After inspecting closely, looks like both of you are using closure.
In your friends case, i
is accessed inside anonymous function 1 and i2
is accessed in anonymous function 2 where the console.log
is present.
In your case you are accessing i2
inside anonymous function where console.log
is present. Add a debugger;
statement before console.log
and in chrome developer tools under "Scope variables" it will tell under what scope the variable is.