This is because the Javascript scope is working under the name of "climb". When the parser reads a Javascript function, it looks through and finds all the variables defined in this area (using the var keyword) (remember that the only kind of area in Javascript is the function area). He then places them at the beginning of the function.
So, the parser interprets your code as follows:
a = false; var k = (function() { var a; console.log(a); a = true console.log(a); }());
(NB I fixed your function call so that it does not return a syntax error.)
Obviously, this now sets a to undefined before it makes the first console.log .
According to MDC :
Each definition of a variable is really a declaration of a variable at the top of its scope and an assignment at the place where that definition is.
source share