Question Bank

JavaScript Hoisting and TDZ Code Traces

Difficulty: Medium

Six traces covering `var` declaration hoisting, function-declaration hoisting, TDZ access of `let`/`const`, and IIFE shadowing. Sharpens the mental model of when a binding exists vs. when it has a value.

Question Bank
/

JavaScript Hoisting and TDZ Code Traces

JavaScript Hoisting and TDZ Code Traces

Six traces covering `var` declaration hoisting, function-declaration hoisting, TDZ access of `let`/`const`, and IIFE shadowing. Sharpens the mental model of when a binding exists vs. when it has a value.

Question Bank
Medium
JavaScript
6 questions
quiz
interview-prep
js-hoisting
js-language

642 views

9

What does the following code print?

Examples

Example 1:

Input: foobar()
Output: undefined
Explanation: The inner var foo declaration is hoisted to the top of the function but its assignment stays in place, so the log reads the local binding before it has a value.