[cut off part from another thread]
Global variables eat memory - local variables exist only as long as the function survives, unless they are in some way referenced from somewhere else. (Mostly the objects that has been created using the function, gíven the function is a constructor.)
Every extra action you have to take - including climbing the scope chain and calling a function - consume processing power. You gain load speed and readability from splitting up in smaller functions, especially if they are called from many places.
Do..while is faster than while is faster than for is faster than for..in. Sometimes a function calling itself is faster than an iterator, sometimes not. Seems to depend on function complexity - the more complex the more gain. If you can keep a loop shorter than a function, use that instead.
setInterval is better than setTimeout. Neither is good.
Don't ever use eval, Function constructor or RegExp constructor if you can avoid them. They are big hogs all of them.
Use break and continue in loops if they perform an action you might be interested in. It's often better to loop through everything and jump what you don't want to handle than to set a more complex expression in the condition of the loop.
Use labled blocks and breaks for complex execution handling. It may be spaghetti, but it's fast.
Minimise actions inside loops. For instance, never use collection.length inside the condition if it's static during the loop - store it in a variable instead.
Last edited by liorean; 11-20-2003 at 01:07 AM..