Q4: How does Hoisting work in JavaScript?
Hoisting is JavaScript's behavior of moving variable and function declarations to the top of their containing scope during creation phase. Function declarations are hoisted with their complete definitions, var declarations are hoisted with undefined, while let and const remain uninitialized in the TDZ.
Key Takeaways
- Function declarations are hoisted with their definitions fully accessible.
varis hoisted asundefined;let/constare placed in the TDZ.
Knowledge Check
What is printed when calling foo() declared as: var foo = function() { return 1; }; before assignment?