JavaScript Function Declarations are fully hoisted. You can call the function anywhere in its scope, even before it appears in the code.
JavaScript Function Expressions (including arrow functions) hoist only their variable declaration, not the assignment. Calling them before definition results in an error.
1. Function Declaration (Fully Hoisted)
2. Function Expression with var (Undefined Error)
var sayHello is hoisted as undefined, so invoking undefined() throws a TypeError.
3. Function Expression with let / const or Arrow Function (Reference Error)
let and const variables enter a Temporal Dead Zone (TDZ) until the execution reaches the definition.

No comments:
Post a Comment