loading...

What's the output?

318097 profile image Mehul Lakhanpal Originally published at codedrops.tech ・1 min read
function func(){
    return foo;

    foo = 1;
    function foo(){}
    var foo = 'hello';
}

console.log(typeof func());

Thanks for reading πŸ’™

Follow @codedrops.tech for daily posts.

Instagram ● Twitter ● Facebook

Micro-Learning ● Web Development ● Javascript ● MERN stack ● Javascript

codedrops.tech

Discussion

pic
Editor guide
Collapse
akh16 profile image
akh16

can you explain, why out is function

Collapse
318097 profile image
Mehul Lakhanpal Author

Ok, so due to hoisting, the variables are put first followed by functions.
So it looks like:

function func(){
    var foo;
    function foo(){};
    return foo;

    foo = 1;
    foo = 'hello';
}