The statement var something = something; works even as the first statement in its scope, because it is equivalent to
var something;
something = something;
and it, as imagined, sets something to undefined, even if something was already defined in an outer scope.
To make a local reference to an object in an outer scope with the same name, it needs to be passed in as a function parameter, because otherwise, the inner name will shadow the outer name because of hoisting.