@ChromiumDev var is functional scope and not block scope as a result all the i's in the console.log will be pointing to the same reference of the i , to solve this you can use let which recreates i on every iteration and will have separate copies of the values.