Generally in for loops you want to declare the variable using a keyword let or var.
Reason for this is when you declare a variable that doesn’t exist yet using somehting like i = 0 without var/let it will create a global variable no matter where you are declaring it which is usually unintended. Normally variables are scoped to the functions/blocks they are in, for example:
function coolFunc() {
let myNum = 20
return myNum;
}
coolFunc() // 20
myNum // myNum is not defined
When you don’t use a keyword, it messes this scoping up though:
function coolFunc() {
myNum = 20
return myNum;
}
coolFunc() // 20
myNum // 20 - this is bad, we don't want myNum to exist globally