JavaScript Hoisting & Temporal Dead Zone Quiz
Tackle 40 questions covering hoisting concepts, var behavior, function declaration hoisting, function expressions, let/const characteristics, temporal dead zone pitfalls, runtime errors, and best practices.
Question 1
What does hoisting describe in JavaScript?
Question 2
What prints here?
console.log(status)
var status = 'ready'Question 3
Why do many developers describe hoisting as a metaphor rather than a literal movement of code?
Question 4
What is logged?
function report() {
console.log(level)
var level = 3
}
report()Question 5
How does var hoisting interact with block statements?
Question 6
What output occurs?
if (true) {
var mode = 'debug'
}
console.log(mode)Question 7
Why is relying on implicit undefined from var hoisting risky?
Question 8
What logs here?
greet()
function greet() {
console.log('hello')
}Question 9
How does function declaration hoisting assist with mutual recursion?
Question 10
What prints?
console.log(typeof describe)
function describe() {
return 'info'
}Question 11
How do function expressions assigned to var behave when accessed before assignment?
Question 12
What happens here?
run()
var run = function () {
console.log('running')
}Question 13
Why do many style guides prefer function declarations for top-level helpers?
Question 14
How can you intentionally avoid hoisting effects when defining utilities?
Question 15
What does this code output?
{
console.log(state)
let state = 'ready'
}Question 16
Which statement about let hoisting is accurate?
Question 17
Why must const declarations be initialized at the point of declaration?
Question 18
What happens?
console.log(total)
const total = 10Question 19
How does block scoping with let/const help avoid hoisting confusion?
Question 20
What does this snippet log?
let flag = true
if (flag) {
console.log(value)
let value = 5
}Question 21
What is the temporal dead zone (TDZ)?
Question 22
What error occurs?
{
console.log(choice)
const choice = 'A'
}Question 23
Why does the TDZ exist for let and const?
Question 24
What is the output?
let ready = false
function toggle() {
if (!ready) {
const ready = true
console.log(ready)
}
}
toggle()
console.log(ready)Question 25
How can TDZ awareness improve code reviews?
Question 26
What happens when this script runs?
(function () {
console.log(item)
let item = 'value'
})()Question 27
Which statement best explains why TDZ errors are preferable to silent undefined values?
Question 28
How can TDZ errors occur in loops?
Question 29
How can bundlers unintentionally introduce TDZ issues?
Question 30
What is logged?
for (let i = 0; i < 2; i += 1) {
console.log(marker)
let marker = i
}Question 31
Which habit reduces hoisting surprises in modules?
Question 32
How can destructuring lead to TDZ issues?
Question 33
Why do many teams enforce eslint rules like no-use-before-define?
Question 34
What does this pattern log?
function init() {
let ready
setup()
ready = true
return ready
function setup() {
console.log(ready)
}
}
console.log(init())Question 35
What best practice keeps TDZ errors out of async code?
Question 36
What result appears?
let config
function prepare() {
config = { ready: true }
}
prepare()
console.log(config.ready)Question 37
How does keeping declarations near their first use help prevent TDZ confusion?
Question 38
Why should you avoid relying on implicit globals when writing modern code?
Question 39
How can TypeScript or Flow assist with hoisting and TDZ issues?
Question 40
What is a simple rule of thumb for avoiding TDZ runtime errors?
