yoklainterview sim

Frontend Javascript Prototypes Oop Interview Questions

75 verified Frontend Javascript Prototypes Oop interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Javascript Prototypes OopDifficulty 1
What is the prototype of a plain object literal like {} by default?
  • aFunction.prototype
  • bObject.prototype
  • cArray.prototype
  • dnull, since object literals start with no prototype
Explanation:Every object literal is implicitly created via new Object(), so its internal [[Prototype]] points to Object.prototype, which is where methods like toString and hasOwnProperty come from. Only Object.create(null) produces an object with no prototype (d).
Javascript Prototypes OopDifficulty 1
function Animal(name) {
  this.name = name;
}
Animal.prototype.speak = function () {
  return this.name + ' makes a noise.';
};
const dog = new Animal('Rex');
console.log(dog.speak());

What does this log?
  • aRex makes a noise.
  • bundefined makes a noise.
  • cTypeError: dog.speak is not a function
  • dmakes a noise.
Explanation:new Animal('Rex') sets this.name = 'Rex' on the new instance, and speak is found by walking up the prototype chain to Animal.prototype. Calling it as dog.speak() binds this to dog, so this.name is 'Rex'.
Javascript Prototypes OopDifficulty 1
What does Object.create(proto) do?
  • aCreates a new object whose prototype is proto
  • bCopies all of proto's properties into a brand-new plain object
  • cFreezes proto and returns the same reference
  • dDefines a new class that extends proto
Explanation:Object.create(proto) returns a fresh object whose internal [[Prototype]] is set to proto — it does not copy properties, it links them. Lookups that miss on the new object fall through to proto.
Javascript Prototypes OopDifficulty 2
const obj = {
  value: 42,
  getValue: function () { return this.value; },
};
const fn = obj.getValue;
console.log(fn());

Assume this runs as a plain (non-strict) script. What is logged?
  • a42
  • bundefined
  • cTypeError: Cannot read properties of undefined
  • dReferenceError: value is not defined
Explanation:fn is called with no receiver, so in non-strict (sloppy) mode this falls back to the global object, which has no value property — this.value is undefined, not an error. In strict mode this would throw (c) instead, because this would be undefined.
Javascript Prototypes OopDifficulty 2
const obj = {
  value: 10,
  regular: function () {
    return (() => this.value)();
  },
};
console.log(obj.regular());

What is logged?
  • a10
  • bundefined
  • cTypeError
  • dNaN
Explanation:Arrow functions have no own this — they capture this lexically from the enclosing scope. The arrow is defined inside regular, so its this is whatever regular's this is, which is obj (called as obj.regular()). So this.value is 10.
Javascript Prototypes OopDifficulty 2
function sum(a, b) {
  return this.base + a + b;
}
console.log(sum.call({ base: 100 }, 1, 2));

What is logged?
  • a3
  • bNaN
  • cTypeError
  • d103
Explanation:Function.prototype.call invokes sum with this explicitly set to { base: 100 }, followed by the remaining arguments passed individually (1, 2). So the result is 100 + 1 + 2 = 103.

Test yourself against the 2925-question Frontend bank.

Start interview