Best Javascript recommend to declare variable at the beginning of the function. Because the variable scope will span the whole function even if they are declared in the middle of the loop.