DEV Community

machy44
machy44

Posted on • Updated on

Temporal Dead Zone

I got a question on the last job interview what is the Temporal Dead Zone. I have not heard about this concept before and as you can guess I did not know the answer. This gave me an idea to write this post about the concept. This post will be short and sweet. Let's get to the point.

What is the Temporal Dead Zone

When you are working with var keyword it will be hoisted and initialized with the undefined value. let and const are also hoisted but they do not get an initial value. Let's see an example:

console.log(varTest); //undefined
var varTest;
console.log(letTest); //ReferenceError: letTest is not defined
let letTest

Maybe this was not the best example but it serves a purpose.

Conclusion

That is the Temporal Dead Zone. Nothing spectacular but now if you hear that term somewhere you will know what is it about.

If you have some thoughts to share or I missed something feel free to comment.

Top comments (0)