Report the value of a variable that was declared but not set.
Acceptance criteria
- 1.#out should show undefined.
JavaScript Tutorial · JavaScript Type System
These 10 tasks go with the JavaScript null and undefined 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: “undefined means a value was never set; null means it was set to nothing on purpose.” .
1.Report an unassigned variableexercise · easy · 10 min
Report the value of a variable that was declared but not set.
Passes when: #out should show undefined.
2.Report a missing propertyexercise · easy · 10 min · practice plan
Read a property that does not exist and report it.
Passes when: #out should show undefined.
3.Empty a value on purposeexercise · easy · 10 min · practice plan
Set a variable to null and report it.
Passes when: #out should show null.
4.Check for eitherexercise · easy · 10 min · practice plan
Use one check that catches both null and undefined.
Passes when: #out should show nothing there.
5.See what JSON keepsexercise · medium · 10 min · practice plan
Stringify an object with a null and an undefined property.
Passes when: #out should show {"a":null}.
6.Fix the check that misses undefinedbug fix · easy · 8 min
Strict equality against null does not catch undefined.
Passes when: #out should show nothing there.
7.Fix the zero rejected as missingbug fix · easy · 8 min · practice plan
A truthy check treats a valid zero as absent.
Passes when: #out should show got 0.
8.Fix typeof used to detect nullbug fix · easy · 8 min · practice plan
typeof null is object, so it cannot identify null.
Passes when: #out should show empty on purpose.
9.Fix the property set to undefinedbug fix · easy · 8 min · practice plan
Setting a property to undefined leaves it in the object but drops it from JSON.
Passes when: #out should show the JSON with a set to null.
10.Fix the wrong emptiness assignedbug fix · easy · 8 min · practice plan
A deliberate emptying should use null, not the text undefined.
Passes when: #out should show really null.
Between them these tasks cover null, undefined and Absence checks.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.