DEV Community

Vaishali JS
Vaishali JS

Posted on

1 1

Lets enter the Temporal Dead Zone 🐱‍👤

We are familiar with variable hoisting in JavaScript. If we try to access a variable (declared using var keyword) before assign it any value, we get undefined. But that's not the case with variables defined using let or const. If we try to access a variable (declared using let or const) before assigning it any value, we get ReferenceError.

Many people believe the reason behind this behavior is that let and const are not hoisted, which is not true. Just like var, they are hoisted, but what they lack is the initialization process which var goes through but let and const do not.

For let and const, initialization is only complete when a value is assigned to the variable; and the period from start of the block scope to initialization of value, where we receive ReferenceError, is known as the Temporal Dead Zone.

Wrapping up: All var, let and const are hoisted. But, unlike var, let and const do not go though initialization process. The time (zone) from start of block scope to actual initialization is called Temporal Dead Zone 🐱‍👤.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay