Actually in this case since you have a function, you could have them declared inside the forEach, but in the while in line 326 you should move them to the top, since this is how JavaScript actually does it. It creates all the variables at the start of the function and initializes them at declaration line. The variables live outside of the loop. I guess it could have some performance reasons, and JSLint also complains about this in the latest version (for while/for cases).