In case of two variables with the same name, the one with innermost scope takes precedence. This little snippet is not a highly practical script. But in general, locals are good. Try to bring variables into existence for as brief a time as possible, that is, to declare them local as late and as deeply as their actual usage warrants. Such practice helps make scope clearer, and reduces the risk of accidental variable name conflicts.
Handlers have scope Handlers also have scope, very much on a par with variables.
It is possible to define a handler inside a handler, and this is very commonly done in order to package the parts of a script into units of single functionality, or to make a utility routine available to be called several times during a script. Here, displayAndWait is a little self-contained handler inside Counter. That fact is good and bad. This might be exactly what you want to do, of course, but it's another one of those cases where with increased power comes increased responsibility. Database entries don't have scope As we saw, database entries are global.