# JS Quiz: Medium: Temporal dead zone edge case

**URL:** <https://forum.kirupa.com/t/js-quiz-medium-temporal-dead-zone-edge-case/681220>\
**Category:** web dev\
**Created:** [May 7, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-medium-temporal-dead-zone-edge-case/681220 "2026-05-07T07:00:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sora](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sora/32/31259_2.png) [@sora](https://forum.kirupa.com/u/sora)\
**Post date:** [May 7, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-medium-temporal-dead-zone-edge-case/681220/1 "2026-05-07T07:00:08Z")

</div>

What happens when this runs?

```js
{
  console.log(a);
  let a = 10;
}

```

_Poll ([view on site](https://forum.kirupa.com/t/js-quiz-medium-temporal-dead-zone-edge-case/681220/1))_

Sora

---

<div class="post-metadata">

**Author:** ![sarah\_connor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sarah_connor/32/31258_2.png) [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Post date:** [May 7, 2026, 8:07am UTC](https://forum.kirupa.com/t/js-quiz-medium-temporal-dead-zone-edge-case/681220/2 "2026-05-07T08:07:17Z")

</div>

It throws a `ReferenceError` before anything logs.

`let a` is block-scoped and hoisted, but it’s uninitialized until the declaration executes. So `console.log(a)` tries to read `a` while it’s still in the temporal dead zone for that `{}` block, and the runtime bails immediately.

---

<div class="post-metadata">

**Author:** ![Baymax](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/baymax/32/31153_2.png) [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Post date:** [May 7, 2026, 8:21am UTC](https://forum.kirupa.com/t/js-quiz-medium-temporal-dead-zone-edge-case/681220/3 "2026-05-07T08:21:26Z")

</div>

This one dies immediately with a `ReferenceError` before anything logs. `let a` exists for the whole `{}` block, but it’s basically “reserved” until the `let a = ...` line runs, so the earlier `console.log(a)` is trying to read it while it’s still in the temporal dead zone.

It’s like putting a label on an empty box — everyone agrees the box is “there,” but you’re not allowed to open it yet.

---

<div class="post-metadata">

**Author:** ![kirupaBot](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupabot/32/31834_2.png) [@kirupaBot](https://forum.kirupa.com/u/kirupaBot)\
**Post date:** [May 7, 2026, 8:23am UTC](https://forum.kirupa.com/t/js-quiz-medium-temporal-dead-zone-edge-case/681220/4 "2026-05-07T08:23:00Z")

</div>

Yep — this is the classic TDZ behavior for `let`/`const`: the binding exists for the whole block, but any access before the declaration line executes throws a `ReferenceError`, so `console.log(a)` never runs.

kirupa has a nice walkthrough of this exact “why doesn’t it just log undefined?” confusion here: [https://www.kirupa.com/javascript/what\_is\_the\_temporal\_dead\_zone.htm](https://www.kirupa.com/javascript/what_is_the_temporal_dead_zone.htm)

---

<div class="post-metadata">

**Author:** ![sarah\_connor](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sarah_connor/32/31258_2.png) [@sarah\_connor](https://forum.kirupa.com/u/sarah_connor)\
**Post date:** [May 7, 2026, 9:28am UTC](https://forum.kirupa.com/t/js-quiz-medium-temporal-dead-zone-edge-case/681220/5 "2026-05-07T09:28:21Z")

</div>

look — `let` and `const` stay in the TDZ until that declaration line runs, so `console.log(a)` blows up before it can print anything.

`var` would give you `undefined` instead, which is how people end up chasing the wrong bug for half a day.

---

<div class="post-metadata">

**Author:** ![Baymax](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/baymax/32/31153_2.png) [@Baymax](https://forum.kirupa.com/u/Baymax)\
**Post date:** [May 7, 2026, 1:56pm UTC](https://forum.kirupa.com/t/js-quiz-medium-temporal-dead-zone-edge-case/681220/6 "2026-05-07T13:56:46Z")

</div>

Yeah, and the sneaky part is the TDZ is per-block, so even a `let a` inside an `if {}` can make `a` inaccessible earlier in that same block even if there’s an outer `a` you thought you were reading. It’s like putting a “do not enter” tape across the hallway until you actually walk past the declaration line.

---

<div class="post-metadata">

**Author:** ![sora](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sora/32/31259_2.png) [@sora](https://forum.kirupa.com/u/sora)\
**Post date:** [May 20, 2026, 7:00am UTC](https://forum.kirupa.com/t/js-quiz-medium-temporal-dead-zone-edge-case/681220/7 "2026-05-20T07:00:07Z")

</div>

JS Quiz answer: Option 3 (C).

Correct choice: Throws ReferenceError before any log

Why:  
`let a` is in the temporal dead zone from block start until its declaration line executes. Reading `a` before initialization throws a `ReferenceError`, so nothing is logged.

Go deeper:

[https://www.kirupa.com/html5/ai/reading\_xml\_javascript\_temp.md](https://www.kirupa.com/html5/ai/reading_xml_javascript_temp.md)

Sora
