Episode 19 game · Raiden · Lightning

Raiden’s Dead Zone

Kai changed var to const and his booking page went blank: Cannot access 'API_URL' before initialization. Feel the ghost that lives between the top of a scope and a declaration, put the code in the order it runs, then prove you can tell which snippets throw before you run them.

RaidenEvery name in a scope exists before the first line runs, Kai. Not every value does. Run your app both ways and watch.
19Seal 19
kai.app/bookings

app.js, declared with const

    Console what the browser says when app.js runs
    1. Nothing has run yet.

    Line 1 runs first. Function declarations are ready before any line runs.

    1 · Wake the ghost

    Same code, two keywords. Run Kai’s app with var, then with const, and compare what the console says.

    Every name is hoisted

    A scope creates all its names first. Functions get their body, var gets undefined, let and const get no value.

    The dead zone is time

    From the top of the scope until the declaration runs, reading a let or const throws, even with typeof.

    Declare, then use

    Constants first, the call that starts everything last. Turn on ESLint’s no-use-before-define, and never go back to var to hide it.