exam questions

Exam 70-480 All Questions

View all questions & answers for the 70-480 exam

Exam 70-480 topic 4 question 17 discussion

Actual exam question from Microsoft's 70-480
Question #: 17
Topic #: 4
[All 70-480 Questions]

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?

  • A. parentObj.instanceof(testObj)
  • B. testObj.isPrototypeOf(parentObj)
  • C. testObj.instanceof(parentObj)
  • D. parentObj.isPrototypeOf(testObj)
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️
The isPrototypeOf() method tests for an object in another object's prototype chain.
Reference: Object.prototype.isPrototypeOf()

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
MrEngineer
Highly Voted 5 years, 7 months ago
Answer should be D https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf
upvoted 10 times
...
Zvonimir
Most Recent 4 years, 5 months ago
answer is C. question is does it inherit (properties, values, ...), not strictly is it one of parent's properties, so I would go with "instanceof"; https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Inheritance
upvoted 1 times
...
elevator44
4 years, 11 months ago
The function must establish whether testObj inherits from another object named parentObj. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf Parameters: The object whose prototype chain will be searched. In this case parameter is testObj because we are looking whether testObj inherits or not so D is correct answer.
upvoted 1 times
...
KyryIx
5 years, 3 months ago
I agree with MrEngineer because <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title></title> </head> <body> <script> // with inheritance function parentObj(){} function testObj(){ parentObj.call(this); } testObj.prototype = new parentObj(); testObj.prototype.constructor = testObj; console.log( testObj.prototype.isPrototypeOf(parentObj) ); // false console.log( parentObj.prototype.isPrototypeOf(testObj) ); // false // with instace function parentObj(){} var testObj = new parentObj(); console.log( parentObj.prototype.isPrototypeOf(testObj) ); // true //console.log( testObj.prototype.isPrototypeOf(parentObj) ); // error </script> </body> </html> // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf
upvoted 4 times
...
Shapespacer
5 years, 5 months ago
Based on that website it suggests that the correct answer is B as if you look for the example of baz. Baz is the object and they search to see if bar exists within the baz prototype chain e.g Bar.prototype.isPrototyeOf(baz). this clearly shows the correct answer being B.
upvoted 4 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...