varto declare your variables. This will work but will make your variables global, which will likely become a source of strange errors later down the road. Always use
Calling your callbacks before you mean to. certain browser API's or libraries expect functions as arguments, don't prematurely call the function before passing it in.
thisto be something else. Often when you create a callback function within another function, the value that's bound to
this- or the context - changes. Understanding how context is bound is helpful here, and often, the simplest fix is to save
thisinto a variable just outside the callback.
Incorrectly making callback functions in loops. Creating callback functions - such as event handlers inside of a loop can get tricky - it may not do what you'd expect if it depends on the loop counter. The solution is to introduce yet another function to act as a closure.
sleep(1)like some other languages to yield execution in the loop. The solution is a mix of task queuing and async programming using