Question · JavaScript and TypeScript course · Module 2: Functions, Arrays and Objects

Variable Hoisting - var vs let

What will happen when we try to use a variable declared with let BEFORE its declaration?

console.log(dinoName); let dinoName = "Rex";

Answer options

  • It will display undefined because let is hoisted with a value of undefined
  • ReferenceError - the variable is in the Temporal Dead Zone (TDZ) until declaration
  • It will display null because let initializes variables with null
  • It will display "Rex" because JavaScript moves the declaration to the top
Show the answer

Correct answer:

  • ReferenceError - the variable is in the Temporal Dead Zone (TDZ) until declaration