Javascript closures and hoisting