You work only within one scope; the loop does not create it, even if you use the var keyword. You simply overwrite your I variable in your current functional area, for example, for example:
for (var i = 0; i < 10; i++) { for (var i = 5; i < 10; i++) { console.log(i); } }
It will just print 5,6,7,8,9.
If you want to create a new scope, you will need to do this using functions, as is usually done in javascript:
for (var i = 0; i < 10; i++) { (function(i) { for (var i = 5; i < 10; i++) { console.log(i); } })(i) }
This will print 5,6,7,8,9 on its lines 10 times.
source share