JavaScript typeof — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript typeof 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 a string type
easy10 minReport the type of a piece of text.
- 2
Show the null quirk
easy10 minReport what typeof gives for null.
- 3
Detect an array
easy10 minUse Array.isArray to tell an array from an object.
- 4
Check an undeclared name
easy10 minReport the type of a variable that was never declared.
- 5
Guard before calling a method
medium10 minOnly uppercase the value when it is really a string.
Find the bug(5)
- 1
Fix typeof compared to a class name
easy8 mintypeof never returns a class name.
- 2
Fix the null check with typeof
easy8 mintypeof null is object, so it cannot detect null.
- 3
Fix the missing quotes
easy8 mintypeof returns a string, so it must be compared with one.
- 4
Fix the guard that runs too late
easy8 minThe method is called before the type is checked.
- 5
Fix the function type check
easy8 minA function reports as function, not object.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace