#84: A function expression's own name
Topic: scope · Difficulty: ★★
const fn = function inner() {};
console.log(typeof inner);
console.log(typeof fn);Output
undefined function
Why
Giving a function expression a name (function inner() {}) creates a binding for that name, but the binding is only visible INSIDE the function's own body — it's added to a special scope wrapped just around the function, used mainly so the function can call itself recursively by that name. It does not leak out into the scope where the expression was written. Outside, the only name in scope is fn, the variable it was assigned to, so typeof inner is 'undefined' out here while typeof fn correctly reports 'function'.