I am going through code snippets of JS hoisting. One of the snippet looks like
var employeeId = 'abc123';
function foo() {
employeeId();
return;
function employeeId() {
console.log(typeof employeeId);
}
}
foo();
The output would be : function
I have read about hoisting and as per my understanding all the variables would be treated as if they are declared at the top of the function and initialised at the line of their actual declaration/definition. In this case the employeeId function identifier would be declared at the top of the function as var employeeId whose value would obviously be undefined and thus the very first line of the function should throw the error.
Please let me know why the output is function?
