Question Bank

let, var, const, and Hoisting Conceptual Quiz

Difficulty: Easy

Walk through the scoping, redeclaration, and hoisting rules for `var`, `let`, and `const`, plus the TDZ trap that shows up in nearly every interview.

Question Bank
/

let, var, const, and Hoisting Conceptual Quiz

let, var, const, and Hoisting Conceptual Quiz

Walk through the scoping, redeclaration, and hoisting rules for `var`, `let`, and `const`, plus the TDZ trap that shows up in nearly every interview.

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

338 views

8

Walk through how var, let, and const differ in scope, redeclaration, and reassignment. Annotate the snippet below with which lines run and which throw.

Examples

Example 1:

Input: var x = 1; var x = 2; let y = 1; let y = 2; const z = 1; z = 2;
Output: var works, let y throws SyntaxError, z = 2 throws TypeError
Explanation: var is function-scoped and re-declarable, let is block-scoped and cannot be redeclared, const additionally rejects reassignment.