JavaScript null and undefined — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript null and undefined 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
Report an unassigned variable
easy10 minReport the value of a variable that was declared but not set.
- 2
Report a missing property
easy10 minRead a property that does not exist and report it.
- 3
Empty a value on purpose
easy10 minSet a variable to null and report it.
- 4
Check for either
easy10 minUse one check that catches both null and undefined.
- 5
See what JSON keeps
medium10 minStringify an object with a null and an undefined property.
Find the bug(5)
- 1
Fix the check that misses undefined
easy8 minStrict equality against null does not catch undefined.
- 2
Fix the zero rejected as missing
easy8 minA truthy check treats a valid zero as absent.
- 3
Fix typeof used to detect null
easy8 mintypeof null is object, so it cannot identify null.
- 4
Fix the property set to undefined
easy8 minSetting a property to undefined leaves it in the object but drops it from JSON.
- 5
Fix the wrong emptiness assigned
easy8 minA deliberate emptying should use null, not the text undefined.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace