Javascript – named function declaration or assign to a variable?

What's the difference between assigning an anonymous javascript function to a variable or just declaring a named function in the first place? Turns out β€œhoisting” of the function only works if you declare it as a named function in the first place. Assigning an anonymous function to a variable doesn't perform the hoist.

(function() {
	console.log(f()); // 'hello'
	function f(){
		return 'hello';
	};
})();

(function() {
	console.log(f()); // undefined
	var f = function() {
		return 'hello';
	};
})();

#javascript