JavaScript Prototype & Inheritance Quiz
Tackle 75 questions covering prototype chain fundamentals, __proto__ vs prototype, constructor functions, adding and overriding prototype methods, Object.create patterns, class syntax with extends/super, distinguishing instance vs prototype data, checking inheritance relationships, understanding this, performance considerations, pitfalls, and best practices.
Question 1
What does the prototype chain represent?
Question 2
Which property references the internal prototype of an object in modern spec terminology?
Question 3
How do you check whether obj inherits from proto?
Question 4
What value terminates every prototype chain?
Question 5
Which statement about Object.prototype is true?
Question 6
What does Object.getPrototypeOf(obj) return?
Question 7
What is the relationship between __proto__ and prototype?
Question 8
Which statement best describes property lookup?
Question 9
What happens if two objects share the same prototype?
Question 10
What does overriding mean in prototypal inheritance?
Question 11
What does the following code log?
const base = { greet() { return 'hi' } }
const obj = Object.create(base)
console.log(obj.greet())Question 12
How can you confirm Object.create(null) produces a prototype-less object?
Question 13
What does this print?
const proto = { value: 42 }
const obj = Object.create(proto)
obj.value = 7
console.log(obj.value, proto.value)Question 14
Why might you use Object.create over new Constructor()?
Question 15
In the code below, what does child.__proto__ reference?
const parent = { role: 'parent' }
const child = Object.create(parent)
console.log(child.__proto__ === parent)Question 16
What is stored in FunctionName.prototype by default?
Question 17
How do instances created via new Constructor() link to the prototype?
Question 18
What does this constructor do?
function Person(name) {
this.name = name
}
Person.prototype.greet = function () {
return `Hi ${this.name}`
}
const bob = new Person('Bob')
console.log(bob.greet())Question 19
Why add methods to Constructor.prototype instead of inside the constructor?
Question 20
What does redefining Constructor.prototype = {} do after instances exist?
function Widget() {}
const a = new Widget()
Widget.prototype = { kind: 'new' }
const b = new Widget()
console.log('a', a.kind, 'b', b.kind)Question 21
What does FunctionName.prototype.constructor typically reference?
Question 22
How do you restore constructor after overriding the prototype object?
Question 23
What does this log?
function Gadget(type) {
this.type = type
}
Gadget.prototype.describe = function () {
return `Type: ${this.type}`
}
const phone = new Gadget('phone')
console.log(phone.describe === Gadget.prototype.describe)Question 24
What is the benefit of Object.getOwnPropertyNames(Constructor.prototype)?
Question 25
What does overriding a prototype method inside an instance do?
Question 26
Which statement about this in prototype methods is correct?
Question 27
Why should instance properties be defined inside the constructor?
Question 28
What does this code demonstrate?
function Counter() {
this.count = 0
}
Counter.prototype.increment = function () {
this.count++
}
const c1 = new Counter()
const c2 = new Counter()
c1.increment()
console.log(c1.count, c2.count)Question 29
What is the effect of deleting an own property?
Question 30
How do you detect whether a property exists anywhere on an object including prototypes?
Question 31
Which method enumerates both own and inherited but enumerable properties?
Question 32
What does this snippet show about method overriding?
function Hero() {}
Hero.prototype.attack = function () {
return 'basic hit'
}
const player = new Hero()
player.attack = function () {
return 'special hit'
}
console.log(player.attack(), Hero.prototype.attack())Question 33
How does overriding affect other instances?
Question 34
What does Object.hasOwn(obj, prop) return?
Question 35
How do prototypes impact memory usage?
Question 36
What does this inheritance pattern do?
function Animal(name) {
this.name = name
}
Animal.prototype.speak = function () {
return `${this.name} makes noise`
}
function Dog(name) {
Animal.call(this, name)
}
Dog.prototype = Object.create(Animal.prototype)
Dog.prototype.constructor = Dog
Dog.prototype.speak = function () {
return `${this.name} barks`
}
const rex = new Dog('Rex')
console.log(rex.speak(), rex instanceof Dog, rex instanceof Animal)Question 37
Why call Animal.call(this, name) inside Dog constructor?
Question 38
What happens if you omit Dog.prototype.constructor = Dog?
function Base() {}
function Sub() {}
Sub.prototype = Object.create(Base.prototype)
const s = new Sub()
console.log(s.constructor === Sub)Question 39
What is Object.create primarily used for?
Question 40
What does this example demonstrate?
const baseConfig = { cache: true }
const envConfig = Object.create(baseConfig)
envConfig.api = '/v1'
console.log(envConfig.cache, envConfig.hasOwnProperty('cache'))Question 41
Which method copies all enumerable properties from sources to target but does not preserve prototype?
Question 42
How does Object.setPrototypeOf affect an object?
const target = { name: 'widget' }
const proto = { type: 'gadget' }
Object.setPrototypeOf(target, proto)
console.log(target.type)Question 43
Why is Object.setPrototypeOf discouraged in hotspots?
Question 44
What does this class syntax compile down to conceptually?
class Shape {
area() { return 0 }
}
class Square extends Shape {
constructor(size) {
super()
this.size = size
}
area() { return this.size ** 2 }
}
const sq = new Square(3)
console.log(sq.area(), sq instanceof Shape)Question 45
What is the role of super in class constructors?
Question 46
What does this class override demonstrate?
class Parent {
speak() { return 'parent' }
}
class Child extends Parent {
speak() {
return super.speak() + ' child'
}
}
const c = new Child()
console.log(c.speak())Question 47
How are class fields defined compared to prototype methods?
Question 48
What does static keyword do in class definitions?
Question 49
What does this static method example log?
class MathUtil {
static square(n) {
return n * n
}
}
console.log(MathUtil.square(4))Question 50
What does Object.getPrototypeOf(ClassName) return for ES classes?
Question 51
How do you create inheritance without constructors using Object.create?
Question 52
What does this factory pattern show?
const base = {
describe() {
return `${this.type} ${this.name}`
}
}
function createPlayer(name) {
const player = Object.create(base)
player.type = 'player'
player.name = name
return player
}
const alice = createPlayer('Alice')
console.log(alice.describe())Question 53
What is the advantage of using Object.create(null) for dictionaries?
Question 54
How does class extends handle the prototype chain?
class A {}
class B extends A {}
const b = new B()
console.log(Object.getPrototypeOf(B) === A, Object.getPrototypeOf(B.prototype) === A.prototype)Question 55
Why prefer class syntax over manual constructor patterns in modern code?
Question 56
How does this behave inside prototype methods when detached?
Question 57
Why can storing functions on prototypes that depend on this be problematic in event handlers?
Question 58
What does this binding example log?
function Timer() {
this.seconds = 0
}
Timer.prototype.tick = function () {
this.seconds++
}
const t = new Timer()
const tick = t.tick
try {
tick()
} catch (e) {
console.log('error')
}
console.log(t.seconds)Question 59
How do you permanently bind a prototype method to an instance?
Question 60
What pitfall arises when assigning mutable objects to prototypes?
Question 61
What does this shared array example show?
function Bag() {}
Bag.prototype.items = []
Bag.prototype.add = function (x) {
this.items.push(x)
}
const b1 = new Bag()
const b2 = new Bag()
b1.add('apple')
console.log(b1.items, b2.items)Question 62
How do you avoid the Bag shared array issue?
Question 63
What does this instanceof check show?
function Animal() {}
function Plant() {}
const a = new Animal()
console.log(a instanceof Animal, a instanceof Plant)Question 64
Why can dynamic prototype reassignment break instanceof?
Question 65
What is a performance consideration for deep prototype chains?
Question 66
Suppose root has level 0, mid inherits from root and overrides level to 1, and leaf inherits from mid without redefining level. What levels are observed from leaf, its prototype, and its prototype’s prototype?
Question 67
Why should you avoid using __proto__ directly?
Question 68
What is a pitfall of mixing class syntax with manual prototype mutations?
Question 69
Which best practice ensures clarity in prototypal design?
Question 70
What does this best-practice example show?
class Queue {
constructor() {
this.items = []
}
enqueue(value) {
this.items.push(value)
}
dequeue() {
return this.items.shift()
}
}
const q1 = new Queue()
const q2 = new Queue()
q1.enqueue('a')
console.log(q1.items, q2.items)Question 71
How can you inspect the entire prototype chain of an object?
Question 72
What does this detection snippet print?
function logChain(obj) {
const chain = []
let current = obj
while (current) {
chain.push(current.constructor && current.constructor.name)
current = Object.getPrototypeOf(current)
}
console.log(chain)
}
logChain(new Date())Question 73
What is a common pitfall when mixing Array inheritance with prototypes?
Question 74
What does this Array subclass output?
class Stack extends Array {
top() {
return this[this.length - 1]
}
}
const stack = new Stack()
stack.push(1, 2)
console.log(stack.top(), stack instanceof Stack, stack instanceof Array)Question 75
Which statement summarizes best practices for prototypal design?
