DEV Community

Mehul Lakhanpal
Mehul Lakhanpal

Posted on • Originally published at codedrops.tech

What's the output?

function func(){
    return foo;

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

console.log(typeof func());
Enter fullscreen mode Exit fullscreen mode

Thanks for reading πŸ’™

Follow @codedrops.tech for daily posts.

Instagram ● Twitter ● Facebook

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

codedrops.tech

Top comments (2)

Collapse
 
akh16 profile image
akh16 • Edited

can you explain, why out is function

Collapse
 
ml318097 profile image
Mehul Lakhanpal

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';
}