Question Bank

JavaScript Variable Hoisting: var vs let/const Explanations Quiz

Difficulty: Medium

Two seeded explanations (var hoisting and the let/const TDZ) plus two companion drills covering function-declaration hoisting and a common interview trap.

Question Bank
/

JavaScript Variable Hoisting: var vs let/const Explanations Quiz

JavaScript Variable Hoisting: var vs let/const Explanations Quiz

Two seeded explanations (var hoisting and the let/const TDZ) plus two companion drills covering function-declaration hoisting and a common interview trap.

Question Bank
Medium
JavaScript
4 questions
quiz
js-hoisting
variables
fundamentals

770 views

9

Explain what variable hoisting means for var declarations and predict the output of the snippet below.

Examples

Example 1:

Input: console.log(num); var num = 10;
Output: undefined
Explanation: The declaration is hoisted to the top of the function or global scope and pre-initialized with undefined; only the assignment stays in place.

Example 2:

Input: foo(); function foo() { console.log('hi'); }
Output: 'hi'
Explanation: Function declarations are hoisted with their body, not just their name, so the call before the declaration still works.