Q:

increment in for loop javascript

I don't know why but I can't increment value in for loop normally.
for (var i = 0; i < 5; i++) {
var number= 0
number++
console.log(number);
}

That's the simple example,and I get 5 times number 1 in console,insted of 0,1,2,3,4.
How I can make that work?

A:

You're declaring the variable inside the loop, so it happens every time the loop runs.  Simply move the declaration outside...
var number = 0;

for (var i = 0; i < 5; i++) {
    number++;
    console.log(number);
}

