What is hoisting in JavaScript?
A
Moving functions to the end of code
C
JavaScript's default behavior of moving declarations to the top
D
Removing unused variables
Analysis & Theory
Hoisting is JavaScript's behavior of moving declarations (not initializations) to the top of their scope.
What is the output of the following code?
```js
console.log(x);
var x = 5;
```
Analysis & Theory
The variable `x` is hoisted but not its value. So `console.log(x)` prints `undefined`.
Which declarations are **not** hoisted to the top?
Analysis & Theory
`let` and `const` are hoisted but not initialized — accessing them before declaration causes `ReferenceError`.
What is the result of this code?
```js
console.log(y);
let y = 10;
```
Analysis & Theory
`let` is hoisted but kept in a 'temporal dead zone' — accessing it before declaration throws `ReferenceError`.
Which of the following **is hoisted**?
Analysis & Theory
Only function declarations are hoisted completely (both definition and body).
What will the following code print?
```js
test();
function test() {
console.log('Hoisted!');
}
```
Analysis & Theory
Function declarations are hoisted with their bodies — so `test()` works before its definition.
What happens with this code?
```js
myFunc();
var myFunc = function() {
console.log('Hello');
};
```
Analysis & Theory
Variable `myFunc` is hoisted as `undefined`, so calling it before it's assigned throws `TypeError`.
Where are `let` and `const` variables hoisted to?
C
Top of their block scope
Analysis & Theory
`let` and `const` are hoisted to the top of their block but are in a 'temporal dead zone' until initialized.
What is a 'temporal dead zone' in JavaScript?
B
Time between hoisting and assignment
D
Time before the browser parses the script
Analysis & Theory
The temporal dead zone is the time between a `let`/`const` variable being hoisted and being initialized.
Which of the following will throw a `ReferenceError`?
A
`console.log(a); var a = 10;`
B
`console.log(b); let b = 20;`
C
`function test() { console.log('Hi'); }`
D
`x = 5; console.log(x);`
Analysis & Theory
`let b = 20` causes a ReferenceError if accessed before declaration.