The point of confusion on #1 is that the function is being made as a function expression. The function is real (so it passes the if statement as truthy) but it's not a function statement, so no external f
reference is created for it.
It's the same concept as when you assign a function to a variable: you're making a function expression.
var g = function(){};
Naming the function expression doesn't actually change that:
var g = function f(){};
// it would still only be externally accessible as g, not f
It would only be accessible as f
from inside the function:
var g = function f(){ alert(f); };
g(); // will call the function, and from inside f will work
To make f
as a function statement (instead of expression) it would have to be defined on its own within its current scope, like so:
function f() {}
// now we can reference it as f externally as a statement!
even just one character in the way and it becomes an expression instead...
!function f() {}
// now we can't :(
For #2, quite simply: delete is for object properties. Such as:
var obj = {};
obj.foo = 'bar';
delete obj.foo;
alert(obj.hasOwnProperty('foo')); // <- false