Report whether the object was built from the class.
Acceptance criteria
- 1.#out should show true.
JavaScript Tutorial · JavaScript Classes
These 10 tasks go with the JavaScript instanceof 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: “instanceof checks whether an object was built from a particular class.” .
1.Check an instanceexercise · easy · 10 min
Report whether the object was built from the class.
Passes when: #out should show true.
2.Follow inheritanceexercise · easy · 10 min · practice plan
Report whether a dog is also an animal.
Passes when: #out should show true.
3.Show it is not symmetricexercise · easy · 10 min · practice plan
Report whether an animal is a dog.
Passes when: #out should show false.
4.Read the exact classexercise · easy · 10 min · practice plan
Report the exact class name of the instance.
Passes when: #out should show Dog.
5.Check behaviour insteadexercise · medium · 10 min · practice plan
Call the method only if the object actually has one.
Passes when: #out should show woof.
6.Fix typeof used to identify a classbug fix · easy · 8 min
typeof only ever says object for an instance.
Passes when: #out should show true.
7.Fix the operands the wrong way roundbug fix · easy · 8 min · practice plan
The object goes on the left and the class on the right.
Passes when: #out should show true.
8.Fix the parent checked as a childbug fix · easy · 8 min · practice plan
A parent instance is not an instance of the child class.
Passes when: #out should show false.
9.Fix instanceof used for the exact classbug fix · easy · 8 min · practice plan
instanceof is true for parents too, so it cannot tell the exact class.
Passes when: #out should show Dog.
10.Fix the class compared as a stringbug fix · easy · 8 min · practice plan
constructor.name is a string, but the class itself is not.
Passes when: #out should show Dog.
Between them these tasks cover instanceof, Type checking and constructor.name.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.