I just encountered this question in one of my interviews. I did not get any answer so putting it on StackOverflow
One simple question in JS but I am not able to get the reason behind it. Below is the code.
var f = function foo(a, b) {
    console.log(a + "-" + b); //f(1,2) will print 1-2
    //foo(1,2) is undefined.
}
Now if I do f(1,2) then it works perfectly fine.
But if I do foo(1,2) then it says undefined function.
Why this is happening? why function can not be called with functions name after assigning the function to js variable?
 
     
     
     
    