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
Read after declaring
easy10 minDeclare a let and read it on the next line.
- 2
Catch a TDZ error
easy10 minUse try and catch to show the word caught when a let is read too early.
- 3
typeof is safe for undeclared names
easy10 minShow what typeof gives for a name that was never declared.
- 4
var has no dead zone
easy10 minShow that a var read before its line is undefined rather than an error.
- 5
Declare at the top of the block
medium10 minDeclare everything before use and return a greeting for Ada.
Find the bug(5)
- 1
Fix the read before the declaration
easy8 minA let cannot be read above its own line.
- 2
Fix the missing catch
easy8 minWithout a catch the error is never turned into a message.
- 3
Fix the const used too early
easy8 minA const has the same dead zone as a let.
- 4
Fix the inner declaration read too soon
easy8 minInside the block, the inner name is in charge from the opening brace.
- 5
Fix the greeting built too early
easy8 minThe 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