Inside a function, you're declaring var myname = "local". Even though you're doing it in the middle of the method, that variable has function scope, so it belongs to the entire function, even the code above it.
So the local variable's value is undefined before that line, and has a value after, but neither one are touching the global variable.