Hint
A function expression with an internal name — visible inside the body only
A Named Function Expression has a name after function, but unlike a declaration, the name is only visible inside the function body — not outside.
// Anonymous function expression — self-reference is fragile
const factorial = function(n) {
if (n <= 1) return 1;
return n * factorial(n - 1); // relies on outer var 'factorial'
};
// If factorial is reassigned, self-reference breaks!
// Named function expression — safe self-reference
const factorial = function fact(n) {
if (n <= 1) return 1;
return n * fact(n - 1); // 'fact' is always THIS function
};
console.log(factorial.name); // 'fact'
console.log(typeof fact); // 'undefined' — not accessible outside!
// If outer var is reassigned, NFE still works
const f = factorial;
factorial = null;
f(5); // 120 — 'fact' still refers to itself correctly