DEV Community

Cover image for One Byte Explainer - Temporal Dead Zone in JavaScript
Pranesh Chowdhury
Pranesh Chowdhury

Posted on

One Byte Explainer - Temporal Dead Zone in JavaScript

This is a submission for the Web Game Challenge: One Byte Explainer

Explainer

TDZ is when a variable is declared but it not yet usable. If you try to use it before it's defined with let or const. You'll get an error. This happens between the start of the code and the point where the variable is defined.

Additional Context

If I have a locked chest (let or const). The chest appears at the start of the level, but you can't open it until you find the key. If you try to open it before getting the key, the game gives an error because of the Temporal Dead Zone.
To avoid trying to use a variable before it's ready just like getting the key before opening the chest.

Top comments (0)