This is because the interpreter makes a distinction between local variables and global variables.
Global variables have values that can be accessed by any function.
The body of a function definition implicitly constitutes a code block. The rule the interpreter follows for evaluating symbols is that inside code blocks local values are always looked for first. If a local value for the variable does not exist, then a global value is sought. If no global value is found then the result is an error. This precedence order can be seen with the following example.