I encountered some confusing issue with using typeof function when the function is declared or when the function is defined as a variable assignment. Here is a sample code:
//This displays "undefined"
console.log(typeof window['a']);
//This displays "function"
console.log(typeof window['b']);
function a() {};
b = function() {};
EDIT: This has nothing to do with hoisting. I have added the following equivalent Node.js code, which is complete so there are no doubts about what else is going on in the program:
function a() {};
b = function() {};
console.log(typeof global['a']);
console.log(typeof global['b']);
The output is:
undefined
function
Can someone explain in light of the above updates why a function declared has no entry in the global/window object?
This is NOT a duplicate. The other questions do not address this specific issue about the returned value of typeof when function is declared as a function or as a variable assignment.