Thought I finally understood hoisting* in JavaScript, but this kind of baffles me. I have noted what I thought is supposed to happen, but can someone explain?
function bar() {
return foo;
foo = 10;
function foo() {}
var foo = '11';
}
UPDATE June 11th 2016
The following is my understanding/abstraction of "hoisting". of the code above, this is not new code.
function bar() {
function foo() {} // value function
var foo; // value undefined;
return foo;
foo = 10; // I believe this will create a global variable if the function is executed
foo = '11'; //local foo is assigned the string value 11
}
alert(typeof bar()); // returns function
*I understand that "hoisting" is this mental construct we have invented to explain the different phases of compiling via the interpreter.