@mabviro omission of the
var keyword is not the problem (if you don't use a strict mode of course). When we do something like
var i = 0 we create a variable
i in the current scope.
i = 0 will try to find variable
i in the scope chain and make the assignation, if variable
i is not present in the upper scopes it will be added as the property to the global object.
Simply speaking - always use
What is the real problem? The
As you probably know we define
for loop by providing three expressions:
- expression that will be executed at the beginning;
- condition that will be checked before starting next iteration;
- expression that will be executed after every iteration.
You have used commas to separate these parts. Because of that, the interpreter is treating
i = count, i < 3, i++ as a single complex expression and is still waiting for two next parts. You can find more about the comma operator here -> MDN: Comma operator.
To fix this problem you just have to change commas in the
for loop to semicolons.