BY Simmi Kava27 Jul 2021 Edit
JavaScript: Temporal Dead Zone (TDZ)

What is Temporal Dead Zone (TDZ)?


TDZ is a term to describe the state of variables where they are not accessible. A variable declared using let & const is in TDZ from the start of the block until the initialization has completed.

A variable defined using let cannot be read/written until they have been full initialized. If no initial value provided, defaults to undefined.

Whereas, variables declared using the keyword var will return a value of undefined if accessed before declaration.

{ //TDZ starts at beginning of scope
console.log(framework); // Returns: undefined
console.log(ranking); // Returns: ReferenceError
var framework = "WebAtoms";
let ranking = "#1"; //TDZ ends here (for ranking)
}

The term "temporal" is used because the zone depends on the time it is executed (order of execution) rather than position(order) where it is declared.

Q) What will happen if we use typeOf operator on a variable which is in TDZ?

A: It will throw a Reference Error. But when a typeOf operator is used on a undeclared or undefined variable, no error is thrown.

MDN Reference Link

Have a nice day!

BY Simmi Kava
LikeCommentSave
LikeCommentSaveShare
0
Categories
General
YantraJS
Developer Guides
Tutorials
Web Atoms Updates

POPULAR POSTS
17 Mar 2021
LATEST ACTIVITY
Simmi Kava
commented this post.
Simmi Kava
liked this post.
Show more
ARCHIVES
2024
2023
2022
2021
TAGS
javascript (56)
developer (25)
javascriptdeveloper (16)
Xamarin.Forms (16)
Html (14)
typescript (12)
webatoms (12)
xamarin (11)
coding (10)
web-atoms (10)
arrays (9)
android (8)
javascript-developer (8)
csharp (7)
dotnet (7)
css (6)
update (6)
dotnet-standard (5)
function (5)
iOS (5)
methods (4)




Web Atoms: JSX (TSX + TypeScript) for Xamarin.Forms, Hot Reload Your App in Production Environment

PlaygroundSamples Repository