My question is - are these rules for scope documented anywhere, or can someone explain how, and why the variable scoping works the way it does?