Hoisting:
console.log(h)
var h = 1
This returns undefined
, since the declaration is moved to the top, but the value is assigned after the console.log()
, just like this:
var h;
console.log(h)
h = 1
This now returns 1, which is don't understand, since it's supposed to be the exact same as above in my understanding
Closure: Why can console.log()
as a function not access the global var h
in the first example?
would be really happy, if sb could help me out here. thank you!