As said before that this is not a recurrsive problem but just how hoisting works with JS.
The code posted you would be executed in the following manner.
(function f(){
function f(){
return 1;
}
function f(){
return 2;
}
return f();
})();
So when the execution reaches the return statement the definition of the function is the second one and hence your return statement is 2 and 1 will never be returned.