Keeping the global namespace free from pollution is important for a lot of reasons – preventing collisions with other imported scripts, and preventing overwrite when using a particular function with a global variable dependency from multiple sources.

Any easy way to avoid this is to pass a function as a variable (although the same technique will usually work with named functions), and redefine it within it’s own executive statements.

For example, say you want a function to increment from 0 and up each time it’s called. Instead of setting the counter outside the function, declare it as a variable local to the function and immediately redefine it.