Common errors
JavaScript · Unit 9: Errors and exceptions
- Full plan
- JavaScript
- 10 exercises
ReferenceError means the name doesn't exist at that point. It happens with a misspelled name, with a variable you use before creating it, or with one that lives inside a {} block and you use it outside.
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Multiple choice
What happens when you call
total([10, 20])?2. Find the case that fails
charge(price)should take off 10 if the price is over 100, and charge the full price otherwise. Which call does it fail with?3. Predict the output
Does it crash or print something?
4. Find the bug
This program should print MIA. Which line has the error?
5. Complete the code
Complete it to print the name in capital letters.
6. Multiple choice
Which of these gives a
ReferenceErrorand not aTypeError?7. Find the bug
This program should add up the points and print 10. Which line has the error?
8. Complete the code
Complete line 2 so the message can change if the grade passes.
9. Put the lines in order
Order the function that returns a person's city, or "No city" if they have no address, without crashing.
10. Predict the output
Does it crash or print something? Think before you answer.
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.