Skip to main content
TOPIC 7 OF 9 · 2 MIN READ

Hoisting and Temporal Dead Zone (TDZ)

Hoisting refers to the process where variable and function declarations are moved to the top of their scope during the creation phase. The Temporal Dead Zone (TDZ) is the period between entering a scope and declaring a variable with let or const.

What you will learn

  • Learn how hoisting affects variables and functions.
  • Understand the concept of Temporal Dead Zone (TDZ) with let and const.

Key concepts

Hoisting

Variables declared with var are hoisted and initialized with undefined. Functions are hoisted with their full definitions.

TDZ

Variables declared with let or const exist in the scope but cannot be accessed before declaration.

Examples

Hoisting:

console.log(a); // undefined
var a = 10;

console.log(b); // ReferenceError (TDZ)
let b = 20;

TDZ:

{
  console.log(x); // ReferenceError
  let x = 5;
}

Practise it

Try these without looking back. If you can explain each one out loud, you are ready for this question.

  • Identify the TDZ in code with let and const.
  • Write examples to demonstrate function and variable hoisting.

Stuck on this one? Talk to Sumit.

Keys: F focus mode · ← → previous / next topic · Esc leave focus