0
0
Javascriptprogramming~5 mins

Prototype inheritance in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is prototype inheritance in JavaScript?
Prototype inheritance is a way objects in JavaScript can share properties and methods through a linked prototype object. When you access a property, JavaScript looks for it on the object, and if not found, it checks the prototype chain.
Click to reveal answer
beginner
How do you set the prototype of an object in JavaScript?
You can set the prototype of an object using Object.create(proto) to create a new object with proto as its prototype, or by using Object.setPrototypeOf(obj, proto).
Click to reveal answer
intermediate
What is the role of constructor in prototype inheritance?
The constructor property points back to the function that created the object. It helps identify the type of the object and is useful when creating new instances.
Click to reveal answer
beginner
Explain the prototype chain in simple terms.
The prototype chain is like a family tree for objects. If an object doesn’t have a property, JavaScript looks up to its prototype, then that prototype’s prototype, and so on, until it finds the property or reaches the end.
Click to reveal answer
beginner
How does JavaScript find a method when you call it on an object?
JavaScript first looks for the method on the object itself. If it’s not there, it looks up the prototype chain until it finds the method or reaches the end (null).
Click to reveal answer
Which of the following is true about prototype inheritance in JavaScript?
AObjects inherit properties directly from other objects via the prototype chain.
BJavaScript uses class-based inheritance only.
CPrototype inheritance copies properties from one object to another.
DPrototype inheritance is not supported in JavaScript.
How can you create a new object that inherits from another object parentObj?
Avar child = Object.assign({}, parentObj);
Bvar child = new Object(parentObj);
Cvar child = parentObj();
Dvar child = Object.create(parentObj);
What does the constructor property of an object refer to?
AThe object's parent in the prototype chain.
BThe function that created the object.
CThe prototype object.
DThe object's own properties.
If a property is not found on an object, where does JavaScript look next?
AIn the object's constructor.
BIn the global variables.
CIn the object's prototype.
DIt throws an error immediately.
What will Object.getPrototypeOf(obj) return?
AThe prototype object of <code>obj</code>.
BThe constructor function of <code>obj</code>.
CThe properties of <code>obj</code>.
DThe global object.
Describe how prototype inheritance works in JavaScript and why it is useful.
Think about how objects share features without copying.
You got /4 concepts.
    Explain how to create an object that inherits from another object and how to access inherited properties.
    Consider how JavaScript finds properties when you use dot notation.
    You got /4 concepts.