Skip to main content

JavaScript Temporal Dead Zone — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Temporal Dead Zone lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.

Exercises(5)

  1. 1

    Read after declaring

    easy10 min

    Declare a let and read it on the next line.

  2. 2

    Catch a TDZ error

    easy10 min

    Use try and catch to show the word caught when a let is read too early.

  3. 3

    typeof is safe for undeclared names

    easy10 min

    Show what typeof gives for a name that was never declared.

  4. 4

    var has no dead zone

    easy10 min

    Show that a var read before its line is undefined rather than an error.

  5. 5

    Declare at the top of the block

    medium10 min

    Declare everything before use and return a greeting for Ada.

Find the bug(5)

  1. 1

    Fix the read before the declaration

    easy8 min

    A let cannot be read above its own line.

  2. 2

    Fix the missing catch

    easy8 min

    Without a catch the error is never turned into a message.

  3. 3

    Fix the const used too early

    easy8 min

    A const has the same dead zone as a let.

  4. 4

    Fix the inner declaration read too soon

    easy8 min

    Inside the block, the inner name is in charge from the opening brace.

  5. 5

    Fix the greeting built too early

    easy8 min

    The greeting word is used before it is declared.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace