Variables & Data Types
Which of the following describes hoisting in JavaScript?
Hoisting in JavaScript refers to the process of moving all variable and function declarations to the top of their containing scope during the compilation phase, before code execution. This means you can use variables and functions before they are declared in your code. However, only the declarations are hoisted, not the initializations. For variables declared with var, they are initialized with undefined when hoisted, but variables declared with let and const are hoisted without initialization (resulting in a ReferenceError if accessed before declaration). Function declarations are fully hoisted, meaning both the declaration and definition are moved to the top.