How you define a function matters. JavaScript offers three distinct patterns for creating logic, each with its own behavior regarding memory and execution.
1The Hoisting Mechanics
When the JavaScript engine runs your code, it performs a 'first pass' where it identifies all function declarations and moves them to the top of the memory space. This is why you can call a function greet() {} before you actually write it in the file. Expressions and Arrows, however, are stored in variables (const or let) and follow the 'Temporal Dead Zone' rules—they do not exist until the execution line is reached.
2Anonymous vs. Named
Named functions are invaluable for debugging. When an error occurs, the 'Stack Trace' will tell you exactly which function failed by name. Anonymous functions (often used as expressions) are 'nameless' in the eyes of the engine. While ES6 tries to infer names for variables, using named declarations for your core application logic is a best practice for enterprise-scale maintenance.
