Declare a let and read it on the next line.
Acceptance criteria
- 1.#out should show ready.
JavaScript Tutorial · JavaScript Scope & Hoisting
These 10 tasks go with the JavaScript Temporal Dead Zone chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “The JavaScript temporal dead zone is the gap between entering a scope and reaching a let or const declaration.” .
1.Read after declaringexercise · easy · 10 min
Declare a let and read it on the next line.
Passes when: #out should show ready.
2.Catch a TDZ errorexercise · easy · 10 min · practice plan
Use try and catch to show the word caught when a let is read too early.
Passes when: #out should show caught.
3.typeof is safe for undeclared namesexercise · easy · 10 min · practice plan
Show what typeof gives for a name that was never declared.
Passes when: #out should show undefined.
4.var has no dead zoneexercise · easy · 10 min · practice plan
Show that a var read before its line is undefined rather than an error.
Passes when: #out should show undefined.
5.Declare at the top of the blockexercise · medium · 10 min · practice plan
Declare everything before use and return a greeting for Ada.
Passes when: #out should show Hello Ada.
6.Fix the read before the declarationbug fix · easy · 8 min
A let cannot be read above its own line.
Passes when: #out should show ready.
7.Fix the missing catchbug fix · easy · 8 min · practice plan
Without a catch the error is never turned into a message.
Passes when: #out should show caught.
8.Fix the const used too earlybug fix · easy · 8 min · practice plan
A const has the same dead zone as a let.
Passes when: #out should show 120.
9.Fix the inner declaration read too soonbug fix · easy · 8 min · practice plan
Inside the block, the inner name is in charge from the opening brace.
Passes when: #out should show inner.
10.Fix the greeting built too earlybug fix · easy · 8 min · practice plan
The greeting word is used before it is declared.
Passes when: #out should show Hello Ada.
Between them these tasks cover Temporal dead zone, let and const errors and Declaration order.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.