A function declaration creates a variable with the same name in the current scope.
function a() {
function b() {
}
}
In the above example, a variable b is created in the scope of a.
A function expression creates a variable with the same name in its own scope.
function a() {
(function b() {
})
}
In the above example, a variable b is created in the scope of b but not a.
In your first example (a named function expression), f doesn't exist outside the function so it is undefined.
In your second example (also a named function express), you are explicitly assigning the function to a (an implicit global) so it is defined.
Neither of your examples features a function declaration, despite your question title. Putting the function keyword inside an if () condition makes it an expression just as much as putting it on the RHS of an =.
typeof fin the first snippet until I remembered it wasn't actually a function declaration.