Hoisting and Execution Context
How does function hoisting differ from variable hoisting in JavaScript?
Function declarations are hoisted completely with their implementation. This differs from variable hoisting, where only the declaration is hoisted but not the assignment. When a function is declared using the function declaration syntax (`function myFunction() {}`), the entire function, including its name, parameters, and body, is hoisted to the top of its scope. This means you can call the function before it appears in your code. For example: ```javascript myFunction(); // This works! function myFunction() { console.log('Hello world'); } ``` However, this only applies to function declarations. Function expressions (like `var myFunction = function() {}`) follow variable hoisting rules: only the variable declaration is hoisted, not the function assignment, so trying to call the function before the assignment would result in a TypeError. This distinction is important to understand when structuring JavaScript code, as it affects when functions become available for execution.