Temporal dead zone (TDZ) and the Deathly Hallows

What is TDZ in javascript?

Temporal dead zone is the period between entering scope and being declared where they cannot be accessed.

An example will give it clear the concept of TDZ. So, for example-

accessDenied = 'can not access'
// <- ReferenceError: accessDenied is not defined
let accessDenied = 'dragons'

here, If we try to access  the variable before it is declared, then the program will throw error.

access = 'can access'
var access = 'success'

In the above example, it will not throw error.

Actually let declarations (and const, which works the same way) may not be hoisted, since accessDenied does not appear to exist before it is assigned a value. let and const are hoisted (like var, class and function), but there is a period between entering scope and being declared where they cannot be accessed (TDZ).

Read more about Temporal Dead zone

 

You May Also Like

About the Author: Md. Delwar Hossain

He has 11 years of experience in developing standalone software and web applications for multiple database platforms. He has been passionate about new tools and technologies. He is positive and trustworthy. He is capable to learn and adapt quickly to different situations. He is a great team player and enjoys leading and mentoring. He is specialized in architecting and building complex web and mobile application. He has strong skills to automate POS, inventory, supply chain, trading export/ import, human resource management, manufacturing and production, distribution management system and hospital management system.

Leave a Reply

Your email address will not be published. Required fields are marked *