Skip to main content

JavaScript Identifiers — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Identifiers 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

    Name a variable clearly

    easy10 min

    Use a descriptive camelCase name and show its value.

  2. 2

    Use an underscore name

    easy10 min

    Underscores are valid in identifiers — prove it.

  3. 3

    Use a dollar sign name

    easy10 min

    A $ is a valid identifier character.

  4. 4

    Use a number inside a name

    easy10 min

    Digits are allowed after the first character.

  5. 5

    Keep names consistent

    medium10 min

    Declare and read the same identifier exactly.

Find the bug(5)

  1. 1

    Fix the name starting with a digit

    easy8 min

    An identifier cannot begin with a number.

  2. 2

    Fix the hyphen in the name

    easy8 min

    A hyphen is read as subtraction, not part of a name.

  3. 3

    Fix the mismatched name

    easy8 min

    The variable is declared one way and read another.

  4. 4

    Fix the space in the name

    easy8 min

    Identifiers cannot contain spaces.

  5. 5

    Fix the reserved word name

    easy8 min

    return cannot be used as a variable name.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace