Report the name when a method is called on null.
Acceptance criteria
- 1.#out should show TypeError.
JavaScript Tutorial · JavaScript Errors
These 10 tasks go with the JavaScript Error Types chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “JavaScript has several built-in error types, each describing a different kind of failure.” .
1.Identify a TypeErrorexercise · easy · 10 min
Report the name when a method is called on null.
Passes when: #out should show TypeError.
2.Identify a ReferenceErrorexercise · easy · 10 min · practice plan
Report the name when a variable does not exist.
Passes when: #out should show ReferenceError.
3.Identify a SyntaxErrorexercise · easy · 10 min · practice plan
Report the name when JSON cannot be parsed.
Passes when: #out should show SyntaxError.
4.Identify a RangeErrorexercise · easy · 10 min · practice plan
Report the name when a value is out of range.
Passes when: #out should show RangeError.
5.React to the typeexercise · medium · 10 min · practice plan
Report a different message depending on the error type.
Passes when: #out should show a type problem.
6.Fix the type compared as textbug fix · easy · 8 min
The name is a string but instanceof needs the class.
Passes when: #out should show a type problem.
7.Fix the wrong type checkedbug fix · easy · 8 min · practice plan
A missing variable is a ReferenceError, not a TypeError.
Passes when: #out should show a missing name.
8.Fix the base class checked firstbug fix · easy · 8 min · practice plan
Every error is an Error, so that branch catches everything.
Passes when: #out should show a type problem.
9.Fix typeof used on an errorbug fix · easy · 8 min · practice plan
typeof reports object for every error.
Passes when: #out should show SyntaxError.
10.Fix the name read from the messagebug fix · easy · 8 min · practice plan
The message describes the problem; the name gives the type.
Passes when: #out should show RangeError.
Between them these tasks cover TypeError, ReferenceError and instanceof.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.