Are you ready?
5 questions to solve
Instructions
- This quiz goes to full-screen once you press the Start button.
- At the end of the quiz, you are able to review all the questions that you answered wrong and see their explanations.
Suppose the variable
Tool
is a function. What will Tool.prototype
return?The
prototype
property of any function points to the prototype object for all the instances of that function. Hence the choice (A).What's the problem in the code below?
function Item(name, price) {
this.name = name;
this.price = price;
}
Item.__proto__.displayInfo = function() {
console.log(this.name + " is for $ " + this.price)
}
var cake = new Item("Chocolate Cake", 10);
cake.displayInfo();
The problem lies in line 5 where we should've written
Item.prototype.displayInfo
instead of Item.__proto__.displayInfo
to get all instances of Item
have the method displayInfo()
available. Hence the choice (A). Refer to Object Prototypes for more info.Determine the prototype of
obj2
from the code below.var obj = {
x: 10,
y: 20
};
var obj2 = Object.create(obj);
Object.create(obj)
creates an object and defines obj
as its prototype. Thus obj2
's prototype is obj
. Refer to Object Prototypes for more info.How can we get to the prototype of the function
Car
? (Remember, we are not talking about the prototype of the instances of Car
.)Refer to the ways of getting an object's prototype in Object Prototypes for more info.
What will be the log made by the following code?
var obj = { x: 10, y: 20 };
var obj2 = {x: 20};
var obj3 = Object.create(obj2)
console.log(obj3.y)
obj3
doesn't have any property y
defined on it, likewise obj3.y
will log. Refer to the ways of getting an object's prototype in Object Prototypes for more info.