JavaScript · Middle · Question 11 of 75
How does obj instanceof Class work?
- ✓Correct answer: It checks whether
Class.prototypeis in the prototype chain ofobj - 2It compares the object's constructor name with the string
Class - 3It checks that the object has all of the class's methods
Explanation
That's why instanceof can give surprising results when prototypes are swapped or for objects from another iframe (they have a different Array.prototype). For arrays, Array.isArray is more reliable.