Programming in HTML5 with JavaScript and CSS3 — Question 36

You are creating a custom function. You pass an object named testObj to the function as a parameter. You do not use inheritance through the functions.
The function must establish whether testObj inherits from another object named parentObj.
You need to ensure that the function performs as required.
Which method or operator should you add to the function?

Answer options

Correct answer: B

Explanation

The correct answer is B, as the isPrototypeOf method checks if the object testObj is in the prototype chain of parentObj. Options A and C incorrectly use instanceof, which checks for the instance of the constructor and not the prototype chain. Option D also misapplies isPrototypeOf by reversing the order of the objects.