When you write b = 1, you're creating a property in the global object.
In an ordinary function, b will refer to this global.
Since your function contains var b;, b within the function refers to the local variable. (var statements create local variables throughout the function, no matter where the var is).
However, the executable portion of the var statement (b = 1) is only executed at that point.