Hidden Names
NFE (Named Function Expression) is when we give a name to a function within a Function Expression.
let sayHi = function func(who) {
if (who) {
alert(`Hello, ${who}`);
} else {
func("Guest"); // Use the internal name for reliable recursion
}
};
Why is this needed?
The name func is accessible ONLY from inside the function itself. This protects you from errors if the sayHi variable gets overwritten externally.
Note
This is mostly useful for recursive calls within functional expressions.
Important
The name property of a function (e.g., sayHi.name) is a built-in JS feature to get the function's name for debugging.