Which approach creates an object that inherits from another?

Prepare for the TJR Bootcamp Test with quizzes and flashcards. Each question includes hints and explanations to boost your readiness for the exam!

Multiple Choice

Which approach creates an object that inherits from another?

Prototypal inheritance is about linking objects so one can read properties from another through a prototype chain. Using Object.create(proto) makes a new object whose internal prototype is the object you pass in, so the new object automatically inherits properties and methods from that object without running a constructor. This is the direct way to establish inheritance between two objects in JavaScript. For example, const parent = { sayHi() { console.log('hi'); } }; const child = Object.create(parent); child.sayHi(); // inherited from parent

Other common operations don’t create such a link. Pushing onto an array just adds an element to that array. Math.random returns a primitive number, not an object with inheritance. JSON.parse turns text into a plain object or array with its default prototype, and it doesn’t establish inheritance from another object unless you manually adjust its prototype after parsing.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy