Define all variables at beginning of function

In JS variables have no block scope and thus they are hoisted to the function's beginning.
I removed the variables from the loop to show where they are initialized first. This has become "best practice" I think (what does not mean that it must be used).
Anyway… I think it helps people understand the code better.