Skip to main content

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. 1

    Report a string type

    easy10 min

    Report the type of a piece of text.

  2. 2

    Show the null quirk

    easy10 min

    Report what typeof gives for null.

  3. 3

    Detect an array

    easy10 min

    Use Array.isArray to tell an array from an object.

  4. 4

    Check an undeclared name

    easy10 min

    Report the type of a variable that was never declared.

  5. 5

    Guard before calling a method

    medium10 min

    Only uppercase the value when it is really a string.

Find the bug(5)

  1. 1

    Fix typeof compared to a class name

    easy8 min

    typeof never returns a class name.

  2. 2

    Fix the null check with typeof

    easy8 min

    typeof null is object, so it cannot detect null.

  3. 3

    Fix the missing quotes

    easy8 min

    typeof returns a string, so it must be compared with one.

  4. 4

    Fix the guard that runs too late

    easy8 min

    The method is called before the type is checked.

  5. 5

    Fix the function type check

    easy8 min

    A 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