JavaScript Prototypes & Inheritance MCQs for Developer Interviews

1 min read

JavaScript implements inheritance exclusively through a prototype-based model rather than traditional class-based mechanics found in languages like Java or C++. Every object in JavaScript contains an internal hidden link known as [[Prototype]] (commonly exposed via proto or Object.getPrototypeOf()) pointing to another object. When a property or method access is attempted, the JavaScript engine searches the object directly; if unassigned, it climbs up the prototype chain recursively until it locates the matching identifier or encounters null. Understanding constructor functions, prototype property bindings, property shadowing, and Object.create() utility behavior is fundamental for mastering JavaScript and clearing senior-level technical interviews.

1. What is a prototype in JavaScript?

a) An object from which other objects inherit properties and methods
b) A class definition blueprint used for static compilation
c) A built-in data type for storing primitive values
d) A function modifier used in asynchronous programming
Correct Answer: a) An object from which other objects inherit properties and methods
Explanation:
Every JavaScript object has an internal link to another object called its prototype, which acts as a fallback storage for property and method lookups.

2. What does the internal `[[Prototype]]` property (accessible via `__proto__` or `Object.getPrototypeOf()`) point to?

a) The prototype object of the constructor that created the instance
b) The global window object
c) The constructor function itself
d) The parent function execution context
Correct Answer: a) The prototype object of the constructor that created the instance
Explanation:
The `[[Prototype]]` reference points directly to the prototype object from which the current object inherits.

3. What is the top-most object in almost all standard JavaScript prototype chains?

a) Object.prototype
b) Function.prototype
c) Global.prototype
d) Null.prototype
Correct Answer: a) Object.prototype
Explanation:
Virtually all standard objects inherit from Object.prototype, whose own internal prototype is `null`, terminating the prototype chain.

4. What is the value of `Object.prototype.__proto__`?

a) null
b) undefined
c) Object
d) Function
Correct Answer: a) null
Explanation:
Object.prototype is at the root of the prototype chain, so its internal prototype reference is explicitly set to `null`.

5. How does property lookup work along the prototype chain when a property is accessed on an object?

a) JavaScript checks the object itself first; if not found, it traverses up the `[[Prototype]]` chain until the property is found or `null` is reached.
b) JavaScript searches the global scope immediately.
c) JavaScript throws a ReferenceError if the property is not on the direct object.
d) JavaScript copies all prototype properties onto the target object first.
Correct Answer: a) JavaScript checks the object itself first; if not found, it traverses up the `[[Prototype]]` chain until the property is found or `null` is reached.
Explanation:
Property access triggers prototype chain delegation, moving upward until the identifier is matched or the chain terminates.

6. What does the `new` keyword do when invoking a constructor function?

a) It creates a new empty object, links its `[[Prototype]]` to the constructor's `prototype` property, binds `this` to the new object, and returns it.
b) It compiles the function into native machine code.
c) It locks the function prototype against modifications.
d) It creates a deep copy of the constructor function.
Correct Answer: a) It creates a new empty object, links its `[[Prototype]]` to the constructor's `prototype` property, binds `this` to the new object, and returns it.
Explanation:
The `new` operator automates instance creation, prototype linking, context binding, and object return.

7. What is the relationship between a constructor function's `prototype` property and an instance's `__proto__`?

a) The instance's `__proto__` points to the constructor function's `prototype` object.
b) They are completely independent memory references.
c) The constructor's `prototype` points to the instance's `__proto__`.
d) They both point to Function.prototype.
Correct Answer: a) The instance's `__proto__` points to the constructor function's `prototype` object.
Explanation:
When created with `new`, the instance inherits from `Constructor.prototype`, establishing `instance.__proto__ === Constructor.prototype`.

8. What does `Object.create(proto)` do?

a) Creates a new object with its internal `[[Prototype]]` explicitly set to the specified `proto` object
b) Creates a deep clone of an existing object
c) Freezes an object against modifications
d) Defines a new constructor function
Correct Answer: a) Creates a new object with its internal `[[Prototype]]` explicitly set to the specified `proto` object
Explanation:
Object.create() is the standard API for pure prototypal inheritance without needing constructor functions.

9. What does the `hasOwnProperty()` method check?

a) Whether a property exists directly on the object itself rather than being inherited along its prototype chain
b) Whether a property exists anywhere in the prototype chain
c) Whether a property is enumerable
d) Whether a property is read-only
Correct Answer: a) Whether a property exists directly on the object itself rather than being inherited along its prototype chain
Explanation:
hasOwnProperty() returns true only for direct (own) properties, ignoring inherited prototype properties.

10. How does the `in` operator behave when checking for a property on an object?

a) It returns true if the property exists on the object itself OR anywhere along its prototype chain.
b) It only checks direct own properties.
c) It checks global scope variables.
d) It throws an error if the property is inherited.
Correct Answer: a) It returns true if the property exists on the object itself OR anywhere along its prototype chain.
Explanation:
The `in` operator tests for property presence across the entire prototype inheritance chain.

11. What is the purpose of `Object.getPrototypeOf(obj)`?

a) Returns the internal prototype (`[[Prototype]]`) of the specified object
b) Returns the constructor function name
c) Returns an array of prototype property keys
d) Returns the prototype chain length as a number
Correct Answer: a) Returns the internal prototype (`[[Prototype]]`) of the specified object
Explanation:
Object.getPrototypeOf() is the standard, recommended method for inspecting an object's prototype.

12. What does `Object.setPrototypeOf(obj, proto)` do?

a) Sets the prototype (`[[Prototype]]`) of a specified object to another object or null
b) Defines static methods on a class
c) Freezes prototype modification
d) Creates a subclass constructor
Correct Answer: a) Sets the prototype (`[[Prototype]]`) of a specified object to another object or null
Explanation:
Object.setPrototypeOf() modifies an object's prototype linkage, though it can impact engine performance if used heavily after object creation.

13. What is the return value of `Array.prototype.isPrototypeOf(myArray)` when `myArray` is `[1, 2, 3]`?

a) true
b) false
c) undefined
d) TypeError
Correct Answer: a) true
Explanation:
isPrototypeOf() checks if an object exists anywhere within another object's prototype chain.

14. What is the constructor property found on prototype objects (e.g., `Person.prototype.constructor`)?

a) A reference back to the constructor function that generated the prototype object
b) A method used to instantiate classes
c) A boolean flag indicating object status
d) An internal garbage collection pointer
Correct Answer: a) A reference back to the constructor function that generated the prototype object
Explanation:
The `constructor` property points back to the function associated with that prototype.

15. What happens if you overwrite a constructor's `prototype` object entirely without resetting its `constructor` property?

a) Instances created from it will point their `constructor` reference to `Object` instead of the original constructor function.
b) An immediate SyntaxError is thrown.
c) Prototypal inheritance becomes disabled permanently.
d) All existing instances are deleted.
Correct Answer: a) Instances created from it will point their `constructor` reference to `Object` instead of the original constructor function.
Explanation:
Replacing `Constructor.prototype = {}` severs the original `constructor` link, inheriting Object's constructor unless explicitly reassigned.

16. How are methods shared efficiently among instances in constructor-based inheritance?

a) By attaching methods to the constructor's `prototype` object rather than inside the constructor function itself
b) By declaring them as global variables
c) By copying methods to every instance during instantiation
d) By using static class properties
Correct Answer: a) By attaching methods to the constructor's `prototype` object rather than inside the constructor function itself
Explanation:
Placing methods on the prototype ensures all instances share a single method reference in memory rather than duplicating function definitions.

17. What is a major downside of defining methods directly inside a constructor function instead of its prototype?

a) Every new instance creates a duplicate copy of the method in memory, wasting resources.
b) Methods cannot access instance properties.
c) Methods become static and immutable.
d) Methods throw a TypeError when invoked.
Correct Answer: a) Every new instance creates a duplicate copy of the method in memory, wasting resources.
Explanation:
Constructor-defined methods are re-instantiated for every `new` call, whereas prototype methods are shared globally by all instances.

18. What is prototypal inheritance?

a) A style of object-oriented programming where objects inherit directly from other objects via prototype delegation
b) Inheritance restricted solely to class-based languages like Java
c) Inheritance managed by compiler preprocessing
d) Inheritance where static variables are shared globally
Correct Answer: a) A style of object-oriented programming where objects inherit directly from other objects via prototype delegation
Explanation:
JavaScript relies on prototypal inheritance, where objects delegate property lookups directly to their prototype objects.

19. How is classical inheritance simulated in ES5 using constructor functions and prototypes?

a) By setting `Child.prototype = Object.create(Parent.prototype)` and restoring `Child.prototype.constructor = Child`
b) By using the `extends` keyword
c) By calling `Parent.call(this)` inside the child constructor
d) Both a and c
Correct Answer: d) Both a and c
Explanation:
Classical inheritance simulation requires prototype chaining (`Object.create`) and constructor borrowing (`Parent.call(this)`).

20. What is the purpose of borrowing a constructor using `Parent.call(this, name)` inside a child constructor function?

a) To execute the parent constructor logic with the child's `this` context, ensuring instance properties are initialized correctly
b) To inherit parent prototype methods
c) To make parent methods static
d) To export the constructor to external modules
Correct Answer: a) To execute the parent constructor logic with the child's `this` context, ensuring instance properties are initialized correctly
Explanation:
Constructor borrowing initializes own properties defined on the parent instance.

21. What happens if you inherit prototype methods using `Child.prototype = new Parent()` instead of `Object.create(Parent.prototype)`?

a) Parent constructor execution side-effects run prematurely, and unwanted parent instance properties become own prototype properties.
b) It creates a syntax error.
c) It is the recommended best practice in ES6.
d) Child instances cannot access parent methods.
Correct Answer: a) Parent constructor execution side-effects run prematurely, and unwanted parent instance properties become own prototype properties.
Explanation:
Using `new Parent()` for inheritance initializes properties on the prototype object unnecessarily, which `Object.create` avoids.

22. What are ES6 classes in JavaScript?

a) Syntactic sugar over JavaScript's existing prototype-based inheritance model
b) A completely new classical object-oriented compilation system
c) Strict type-checked structural interfaces
d) Server-side thread worker wrappers
Correct Answer: a) Syntactic sugar over JavaScript's existing prototype-based inheritance model
Explanation:
ES6 classes do not introduce a new object model; they provide a cleaner, more readable syntax for constructor functions and prototypes.

23. What is the output of `typeof Person` where `Person` is an ES6 class?

a) "function"
b) "object"
c) "class"
d) "undefined"
Correct Answer: a) "function"
Explanation:
Classes in JavaScript are special types of functions under the hood.

24. Are ES6 class declarations hoisted like function declarations?

a) Classes are hoisted to the scope top, but they remain uninitialized in the Temporal Dead Zone, throwing a ReferenceError if accessed before declaration.
b) Yes, they are fully hoisted with initialization like var.
c) No, they are never hoisted at all.
d) They are hoisted into the global window object automatically.
Correct Answer: a) Classes are hoisted to the scope top, but they remain uninitialized in the Temporal Dead Zone, throwing a ReferenceError if accessed before declaration.
Explanation:
Class declarations exhibit TDZ behavior similar to `let` and `const`.

25. How do you define a static method in an ES6 class?

a) Using the `static` keyword before the method name, e.g., `static create() {}`
b) Using the `global` keyword
c) Defining it outside the class body
d) Static methods are not supported in ES6 classes.
Correct Answer: a) Using the `static` keyword before the method name, e.g., `static create() {}`
Explanation:
Static methods belong to the class constructor function itself rather than class instances.

26. Can class instances access static methods defined on their class?

a) No, static methods are called on the class constructor itself, not on instantiated objects.
b) Yes, via the `this` keyword inside instance methods.
c) Yes, through `instance.staticMethod()`.
d) Only if inherited through prototype chain.
Correct Answer: a) No, static methods are called on the class constructor itself, not on instantiated objects.
Explanation:
Static methods are utility functions attached to the class constructor, inaccessible from instance objects.

27. What is the role of the `super` keyword inside an ES6 class subclass constructor?

a) To call the parent class constructor and bind its prototype context before accessing `this`
b) To declare static constants
c) To export the subclass to modules
d) To delete inherited methods
Correct Answer: a) To call the parent class constructor and bind its prototype context before accessing `this`
Explanation:
Derived subclass constructors must execute `super()` before referencing `this`.

28. What happens if you omit `super()` in a derived subclass constructor in ES6?

a) A ReferenceError is thrown when attempting to instantiate the subclass.
b) The parent constructor runs automatically.
c) It defaults to inheriting from Object.
d) It compiles successfully without issues.
Correct Answer: a) A ReferenceError is thrown when attempting to instantiate the subclass.
Explanation:
Subclasses must invoke `super()` in their constructor to initialize parent instance bindings.

29. What are property descriptors in JavaScript?

a) Objects that define the internal attributes of a property, such as writable, enumerable, configurable, and value.
b) Documentation comments attached to classes
c) Type definitions for TypeScript compilation
d) Error logs generated during prototype lookups
Correct Answer: a) Objects that define the internal attributes of a property, such as writable, enumerable, configurable, and value.
Explanation:
Property descriptors give granular control over property behavior using `Object.defineProperty()`.

30. What does setting `enumerable: false` on a property achieve?

a) The property is hidden from loops like `for...in` and methods like `Object.keys()`.
b) The property value cannot be modified.
c) The property cannot be deleted.
d) The property is deleted automatically by garbage collection.
Correct Answer: a) The property is hidden from loops like `for...in` and methods like `Object.keys()`.
Explanation:
Non-enumerable properties are skipped during iteration enumerations.

31. What does setting `writable: false` on a property do?

a) Prevents the property value from being changed via assignment operators
b) Hides the property from `for...in` loops
c) Prevents the property from being deleted
d) Makes the property private to closures
Correct Answer: a) Prevents the property value from being changed via assignment operators
Explanation:
A read-only property (`writable: false`) throws an error in strict mode when reassignment is attempted.

32. What does setting `configurable: false` on a property prevent?

a) The property cannot be deleted, and its descriptor attributes (except writable) cannot be changed.
b) The property value cannot be read.
c) The property cannot be inherited.
d) The object cannot be instantiated.
Correct Answer: a) The property cannot be deleted, and its descriptor attributes (except writable) cannot be changed.
Explanation:
Non-configurable properties are locked down against structural descriptor modifications and deletion.

33. Which method returns the property descriptor for an own property of an object?

a) Object.getOwnPropertyDescriptor(obj, prop)
b) Object.getProperty(obj, prop)
c) Object.getDescriptor(obj)
d) Reflect.descriptor(obj, prop)
Correct Answer: a) Object.getOwnPropertyDescriptor(obj, prop)
Explanation:
Object.getOwnPropertyDescriptor retrieves the attribute configuration of a specific own property.

34. What does `Object.freeze(obj)` do to an object's properties?

a) Makes the object immutable: existing properties cannot be added, deleted, or modified, and their descriptors are set to non-writable and non-configurable.
b) Deletes all prototype links.
c) Converts all properties to private fields.
d) Clears all methods from memory.
Correct Answer: a) Makes the object immutable: existing properties cannot be added, deleted, or modified, and their descriptors are set to non-writable and non-configurable.
Explanation:
Object.freeze provides shallow immutability across an object's own properties.

35. What is the difference between `Object.freeze()` and `Object.seal()`?

a) Freeze prevents property modification and makes properties non-writable, whereas seal prevents adding/deleting properties but allows existing properties to be modified.
b) Seal makes objects deeply frozen recursively.
c) Freeze only applies to arrays.
d) There is no difference between them.
Correct Answer: a) Freeze prevents property modification and makes properties non-writable, whereas seal prevents adding/deleting properties but allows existing properties to be modified.
Explanation:
Sealed objects allow mutating values of existing writable properties, while frozen objects lock those down as well.

36. What does `Object.preventExtensions(obj)` do?

a) Prevents any new properties from ever being added to the object
b) Freezes all existing property values
c) Removes all prototype links
d) Deletes non-enumerable properties
Correct Answer: a) Prevents any new properties from ever being added to the object
Explanation:
Preventing extensions locks the object's shape, though existing properties can still be modified or deleted.

37. What are getter and setter accessor properties in objects?

a) Special functions defined in property descriptors that intercept property retrieval (get) and assignment (set).
b) Private class methods only accessible via subclasses.
c) Methods used to convert objects into JSON strings.
d) Asynchronous promise handlers for property loading.
Correct Answer: a) Special functions defined in property descriptors that intercept property retrieval (get) and assignment (set).
Explanation:
Getters and setters allow computed property access and validation during assignment.

38. How do you define a getter property inside an ES6 class?

a) Using the `get` keyword before the method name, e.g., `get area() { return this.w * this.h; }`
b) Using `getter method()` syntax
c) Prefixing with `read`
d) Getters are not supported in ES6 classes.
Correct Answer: a) Using the `get` keyword before the method name, e.g., `get area() { return this.w * this.h; }`
Explanation:
ES6 getter methods are accessed like properties without parentheses (`obj.area`).

39. What is prototypal inheritance delegation compared to classical copying?

a) Delegation links objects dynamically to a prototype fallback chain, whereas classical inheritance traditionally copies properties or structures down a hierarchy.
b) Delegation copies all methods into instance memory.
c) Classical inheritance is dynamic, while prototypal is static.
d) There is no functional difference.
Correct Answer: a) Delegation links objects dynamically to a prototype fallback chain, whereas classical inheritance traditionally copies properties or structures down a hierarchy.
Explanation:
JavaScript uses dynamic delegation rather than structural class-based copying.

40. What is the output of `[1, 2].__proto__ === Array.prototype`?

a) true
b) false
c) undefined
d) TypeError
Correct Answer: a) true
Explanation:
Array instances inherit directly from Array.prototype.

41. What is the prototype of `Array.prototype`?

a) Object.prototype
b) Function.prototype
c) null
d) Array
Correct Answer: a) Object.prototype
Explanation:
Array.prototype is an object, so its internal prototype points to Object.prototype.

42. What is monkey patching in JavaScript?

a) Modifying or extending built-in prototype objects (like `Array.prototype`) at runtime
b) A security vulnerability in prototype chains
c) A compiler optimization technique in V8
d) An error handling pattern for asynchronous promises
Correct Answer: a) Modifying or extending built-in prototype objects (like `Array.prototype`) at runtime
Explanation:
Monkey patching adds custom methods to native prototypes, though it is generally discouraged due to global scope pollution risks.

43. Why is modifying native built-in prototypes (monkey patching) generally discouraged in production code?

a) It risks naming collisions with future language specifications or third-party libraries, leading to subtle bugs.
b) It causes memory leaks in the garbage collector.
c) It makes the code execute 10x slower.
d) It throws an immediate SyntaxError.
Correct Answer: a) It risks naming collisions with future language specifications or third-party libraries, leading to subtle bugs.
Explanation:
Modifying built-in prototypes globally can pollute codebases and conflict with future ECMAScript additions.

44. What is a mixin pattern in JavaScript prototypal inheritance?

a) A pattern where methods from multiple independent object sources are copied or combined into a target prototype or object
b) A method for mixing CSS styles with DOM elements
c) A class extension keyword
d) A function that merges two arrays
Correct Answer: a) A pattern where methods from multiple independent object sources are copied or combined into a target prototype or object
Explanation:
Mixins enable horizontal code reuse across disparate prototype chains since JavaScript does not support classical multiple inheritance.

45. What is parasitic inheritance?

a) An inheritance pattern where an object constructor parasitically absorbs methods from another object and enhances them before returning
b) A memory leak caused by dangling prototype links
c) A virus infecting prototype chains
d) Inheritance where child classes destroy parent classes
Correct Answer: a) An inheritance pattern where an object constructor parasitically absorbs methods from another object and enhances them before returning
Explanation:
Parasitic inheritance takes an existing object, augments it with custom methods, and returns it as a new enhanced instance.

46. What is the prototype chain lookup performance impact of deep, multi-level inheritance?

a) Deep prototype chains can slow down property resolution if the engine has to traverse many levels, though modern engines optimize this heavily using hidden classes.
b) It causes stack overflow errors immediately.
c) It has zero performance impact.
d) It disables garbage collection entirely.
Correct Answer: a) Deep prototype chains can slow down property resolution if the engine has to traverse many levels, though modern engines optimize this heavily using hidden classes.
Explanation:
While traversal adds overhead, modern JS engines use inline caches and hidden classes to optimize property access speed.

47. What are hidden classes (Shapes / Structures) in V8 regarding prototype objects?

a) Internal engine structures used to optimize property offsets and avoid slow dictionary lookups on objects with matching prototype shapes.
b) ES6 class definitions hidden from reflection.
c) Private class fields.
d) Encrypted constructor functions.
Correct Answer: a) Internal engine structures used to optimize property offsets and avoid slow dictionary lookups on objects with matching prototype shapes.
Explanation:
Hidden classes allow JIT compilers to optimize property lookups based on object shape consistency.

48. What happens if you add properties to an object after its creation in terms of V8 hidden classes?

a) It transitions the object to a new hidden class shape, which can degrade optimization if done frequently.
b) It freezes the object automatically.
c) It throws a TypeError.
d) It resets the prototype chain to null.
Correct Answer: a) It transitions the object to a new hidden class shape, which can degrade optimization if done frequently.
Explanation:
Dynamically adding properties forces shape transitions, highlighting why defining object shapes in constructors is efficient.

49. What is the difference between `Object.keys()` and `for...in` loop regarding inherited prototype properties?

a) `Object.keys()` returns only own enumerable properties, whereas `for...in` iterates over both own and inherited enumerable properties along the prototype chain.
b) `Object.keys()` iterates over prototype properties as well.
c) `for...in` ignores all enumerable properties.
d) There is no difference between them.
Correct Answer: a) `Object.keys()` returns only own enumerable properties, whereas `for...in` iterates over both own and inherited enumerable properties along the prototype chain.
Explanation:
Object.keys restricts results to direct properties, while for...in traverses the prototype chain.

50. What does `Object.getOwnPropertyNames()` return?

a) An array of all own property names (both enumerable and non-enumerable) found directly on the object
b) All inherited prototype properties
c) Only enumerable own properties
d) Symbol property keys only
Correct Answer: a) An array of all own property names (both enumerable and non-enumerable) found directly on the object
Explanation:
getOwnPropertyNames includes non-enumerable own properties, excluding inherited ones.

51. How do Symbol properties interact with prototype inheritance and iteration?

a) Symbol properties can be inherited via prototypes, but they are ignored by standard enumeration methods like `Object.keys()` and `for...in` loops.
b) Symbols cannot be inherited.
c) Symbols are automatically enumerable everywhere.
d) Symbols terminate prototype chain lookups.
Correct Answer: a) Symbol properties can be inherited via prototypes, but they are ignored by standard enumeration methods like `Object.keys()` and `for...in` loops.
Explanation:
Symbols require special iteration methods like `Object.getOwnPropertySymbols()`.

52. What is the purpose of `Reflect.ownKeys(obj)`?

a) Returns an array of all own property keys, including both strings and symbols, as well as enumerable and non-enumerable properties.
b) Returns all inherited prototype keys.
c) Returns object values.
d) Returns prototype object references.
Correct Answer: a) Returns an array of all own property keys, including both strings and symbols, as well as enumerable and non-enumerable properties.
Explanation:
Reflect.ownKeys combines string and symbol own keys into a single comprehensive array.

53. Can primitive data types (like numbers or strings) have prototypes in JavaScript?

a) Yes, JavaScript temporarily boxes primitives into wrapper objects, granting them access to prototype methods like `.toFixed()` or `.toUpperCase()`.
b) No, primitives have no prototype linkage whatsoever.
c) Only strings have prototypes; numbers do not.
d) Primitives throw a TypeError if prototype methods are accessed.
Correct Answer: a) Yes, JavaScript temporarily boxes primitives into wrapper objects, granting them access to prototype methods like `.toFixed()` or `.toUpperCase()`.
Explanation:
Autoboxing wraps primitives in temporary wrapper objects during method access, utilizing prototype methods.

54. What is the prototype of a primitive string value when evaluated via `__proto__`?

a) String.prototype
b) Object.prototype
c) Function.prototype
d) null
Correct Answer: a) String.prototype
Explanation:
Boxed string instances inherit from String.prototype.

55. What is the output of `typeof Object.create(null)`?

a) "object"
b) "undefined"
c) "null"
d) "function"
Correct Answer: a) "object"
Explanation:
Object.create(null) creates a dictionary object with a null prototype (`[[Prototype]]: null`).

56. What is a dictionary object created with `Object.create(null)` devoid of?

a) It lacks any prototype chain, meaning it does not inherit built-in methods like `toString()`, `hasOwnProperty()`, or `valueOf()`.
b) It lacks the ability to store key-value pairs.
c) It cannot have properties added to it.
d) It lacks memory allocation.
Correct Answer: a) It lacks any prototype chain, meaning it does not inherit built-in methods like `toString()`, `hasOwnProperty()`, or `valueOf()`.
Explanation:
Null-prototype objects are completely clean dictionaries free of prototype pollution risks and inherited methods.

57. What is prototype pollution vulnerability in JavaScript?

a) A security exploit where an attacker injects properties into `Object.prototype`, unintentionally altering the behavior of all objects in the application.
b) A memory leak caused by unreferenced prototype links
c) A syntax error in ES6 classes
d) An overflow in the microtask queue
Correct Answer: a) A security exploit where an attacker injects properties into `Object.prototype`, unintentionally altering the behavior of all objects in the application.
Explanation:
Prototype pollution occurs when untrusted input modifies shared prototypes like Object.prototype, compromising application security.

58. How can you mitigate prototype pollution risks in JavaScript applications?

a) By using null-prototype objects (`Object.create(null)`), freezing Object.prototype, or validating recursive object merging operations.
b) By using `var` instead of `const`.
c) By disabling strict mode.
d) By converting all objects into arrays.
Correct Answer: a) By using null-prototype objects (`Object.create(null)`), freezing Object.prototype, or validating recursive object merging operations.
Explanation:
Defensive programming practices like freezing prototypes or sanitizing keys prevent prototype pollution.

59. What is the prototype of a newly created function in JavaScript (e.g., `function f() {}`)?

a) Function.prototype
b) Object.prototype
c) null
d) Array.prototype
Correct Answer: a) Function.prototype
Explanation:
All functions inherit from Function.prototype.

60. What is the prototype of `Function.prototype`?

a) Object.prototype
b) null
c) Function
d) Array.prototype
Correct Answer: a) Object.prototype
Explanation:
Function.prototype is an object, so its prototype points to Object.prototype.

61. What is the output of `Function.__proto__ === Function.prototype`?

a) true
b) false
c) undefined
d) TypeError
Correct Answer: a) true
Explanation:
The constructor function `Function` is an instance of itself, so its `__proto__` points to Function.prototype.

62. Can arrow functions be used as constructor functions with the `new` keyword?

a) No, arrow functions lack a `prototype` property and throw a TypeError if invoked with `new`.
b) Yes, they create instances normally.
c) Only if defined inside an ES6 class.
d) Yes, but they inherit from Object by default.
Correct Answer: a) No, arrow functions lack a `prototype` property and throw a TypeError if invoked with `new`.
Explanation:
Arrow functions do not have a `prototype` property and cannot be instantiated as constructors.

63. Do arrow functions have their own `prototype` property?

a) No, arrow functions have `undefined` for their `prototype` property.
b) Yes, they inherit from Function.prototype.
c) Yes, they point to Object.prototype.
d) Only when used as methods.
Correct Answer: a) No, arrow functions have `undefined` for their `prototype` property.
Explanation:
Arrow functions do not maintain a prototype object because they cannot be used as constructors.

64. What is method stealing (borrowing) using `call()` or `apply()`?

a) Invoking a method defined on one prototype or object using an entirely different object as its `this` context.
b) Stealing private class fields from external modules
c) Overwriting prototype methods maliciously
d) Copying class definitions across files
Correct Answer: a) Invoking a method defined on one prototype or object using an entirely different object as its `this` context.
Explanation:
Method borrowing allows array methods to operate on array-like objects.

65. How does `Object.assign(target, ...sources)` handle inherited properties from source objects?

a) It ignores inherited prototype properties, copying only enumerable own properties from the sources.
b) It copies the entire prototype chain recursively.
c) It throws an error if sources have prototypes.
d) It converts inherited properties into own properties.
Correct Answer: a) It ignores inherited prototype properties, copying only enumerable own properties from the sources.
Explanation:
Object.assign operates exclusively on own enumerable properties.

66. How does `structuredClone()` handle prototype chains when deep cloning an object?

a) It strips prototype chains, returning a plain object whose prototype is Object.prototype.
b) It preserves custom prototype inheritance fully.
c) It throws a TypeError for objects with prototypes.
d) It copies prototype methods into instance properties.
Correct Answer: a) It strips prototype chains, returning a plain object whose prototype is Object.prototype.
Explanation:
structuredClone discards custom prototype information, returning standard plain data objects.

67. What is the purpose of the `instanceof` operator?

a) To test whether a constructor's `prototype` property appears anywhere within an object's prototype chain
b) To check the exact primitive data type of a variable
c) To verify if an object has own properties
d) To compare two objects for reference equality
Correct Answer: a) To test whether a constructor's `prototype` property appears anywhere within an object's prototype chain
Explanation:
The `instanceof` operator evaluates prototype chain membership against a constructor function.

68. How can you override the default behavior of the `instanceof` operator for a custom class?

a) By defining a static `[Symbol.hasInstance](instance)` method on the class.
b) By overriding `__proto__` manually.
c) By setting `instanceof = false`.
d) Instanceof behavior cannot be customized.
Correct Answer: a) By defining a static `[Symbol.hasInstance](instance)` method on the class.
Explanation:
The `Symbol.hasInstance` well-known symbol allows customizing `instanceof` logic.

69. What is the prototype of an instantiated ES6 class object?

a) The class's `prototype` property object
b) Function.prototype
c) Object.prototype
d) null
Correct Answer: a) The class's `prototype` property object
Explanation:
Instances of an ES6 class inherit from `ClassName.prototype`.

70. What is the prototype of an ES6 class constructor function itself?

a) Function.prototype (or the parent class constructor if extending)
b) Object.prototype
c) null
d) ClassName.prototype
Correct Answer: a) Function.prototype (or the parent class constructor if extending)
Explanation:
Since classes are functions, the class constructor function inherits from Function.prototype, and static inheritance links child class to parent class.

71. What is static inheritance in ES6 classes?

a) Subclasses inherit static methods and properties from their parent class via prototype linkage of the constructor functions themselves.
b) Inheriting instance methods without instantiating objects
c) Sharing global variables across modules
d) Locking class properties against modification
Correct Answer: a) Subclasses inherit static methods and properties from their parent class via prototype linkage of the constructor functions themselves.
Explanation:
Extending a class links the child constructor's `[[Prototype]]` to the parent constructor, enabling static method inheritance.

72. Can instance methods access static methods directly using `this`?

a) No, `this` inside an instance method refers to the instance object, not the constructor function where static methods reside.
b) Yes, automatically.
c) Only in strict mode.
d) Yes, via `super.staticMethod()`.
Correct Answer: a) No, `this` inside an instance method refers to the instance object, not the constructor function where static methods reside.
Explanation:
Instance methods operate on instances, whereas static methods operate on the class constructor.

73. Can static methods access instance properties using `this`?

a) No, `this` inside a static method refers to the class constructor function itself, which has no access to specific instance properties.
b) Yes, if the instance is created first.
c) Yes, automatically for all instances.
d) Only when using arrow functions.
Correct Answer: a) No, `this` inside a static method refers to the class constructor function itself, which has no access to specific instance properties.
Explanation:
Static `this` points to the class constructor, so it cannot access individual instance states directly without an instance argument.

74. What are private class fields in ES2022 (`#field`)?

a) Class properties prefixed with `#` that are strictly encapsulated within the class body and inaccessible from outside or via prototype chains.
b) Properties hidden using `enumerable: false`.
c) Properties stored in global scope.
d) Constants declared with `const` inside constructors.
Correct Answer: a) Class properties prefixed with `#` that are strictly encapsulated within the class body and inaccessible from outside or via prototype chains.
Explanation:
Private fields provide true language-level encapsulation, inaccessible via inheritance or external prototype inspection.

75. Can private class fields be inherited by subclasses?

a) No, private fields are strictly scoped to the declaring class and cannot be accessed or inherited by subclasses.
b) Yes, automatically through prototype delegation.
c) Yes, if declared with `protected` keyword.
d) Only via `super.#field`.
Correct Answer: a) No, private fields are strictly scoped to the declaring class and cannot be accessed or inherited by subclasses.
Explanation:
Private fields (`#`) are not part of the prototype chain and cannot be accessed by subclasses.

76. What is the purpose of the `Object.isPrototypeOf()` method?

a) To check if an object exists within another object's prototype chain
b) To check if two objects share the exact same constructor function
c) To verify if an object is frozen
d) To compare two prototype objects for deep equality
Correct Answer: a) To check if an object exists within another object's prototype chain
Explanation:
isPrototypeOf() tests whether the calling object exists in the prototype chain of the argument.

77. What is the return value of `Object.prototype.isPrototypeOf({})`?

a) true
b) false
c) undefined
d) TypeError
Correct Answer: a) true
Explanation:
Object.prototype is in the prototype chain of all standard objects like `{}`.

78. What is the return value of `Object.prototype.isPrototypeOf(Object.create(null))`?

a) false
b) true
c) TypeError
d) undefined
Correct Answer: a) false
Explanation:
Objects created with `Object.create(null)` have a null prototype, meaning Object.prototype is not in their chain.

79. What is the prototype of a newly created Array instance (`[]`)?

a) Array.prototype
b) Object.prototype
c) Function.prototype
d) null
Correct Answer: a) Array.prototype
Explanation:
Array instances inherit directly from Array.prototype.

80. What is the prototype of a newly created RegExp instance (`/abc/`)?

a) RegExp.prototype
b) Object.prototype
c) Function.prototype
d) String.prototype
Correct Answer: a) RegExp.prototype
Explanation:
Regular expression objects inherit from RegExp.prototype.

81. What is the prototype of a newly created Error instance (`new Error()`)?

a) Error.prototype
b) Object.prototype
c) Function.prototype
d) Exception.prototype
Correct Answer: a) Error.prototype
Explanation:
Error objects inherit from Error.prototype.

82. How do custom Error classes inherit correctly in ES6?

a) By extending `Error` (`class MyError extends Error {}`), ensuring stack traces and prototype chains are wired properly.
b) By returning a string from constructor.
c) By monkey patching Object.prototype.
d) Custom error inheritance is unsupported.
Correct Answer: a) By extending `Error` (`class MyError extends Error {}`), ensuring stack traces and prototype chains are wired properly.
Explanation:
Extending Error ensures proper prototype chaining and correct stack trace generation for custom errors.

83. What is the output of `typeof Object.prototype`?

a) "object"
b) "function"
c) "undefined"
d) "prototype"
Correct Answer: a) "object"
Explanation:
Object.prototype is a standard built-in object, unlike constructor functions which evaluate to "function".

84. What is the output of `typeof Function.prototype`?

a) "function" (in most engines for historical reasons, though spec-defined as callable)
b) "object"
c) "undefined"
d) "prototype"
Correct Answer: a) "function" (in most engines for historical reasons, though spec-defined as callable)
Explanation:
Function.prototype is a callable function object in JavaScript for historical compatibility reasons.

85. What is the prototype of `Function.prototype`?

a) Object.prototype
b) null
c) Function
d) Array.prototype
Correct Answer: a) Object.prototype
Explanation:
Function.prototype inherits from Object.prototype.

86. What is the ultimate root of all prototype chains in JavaScript?

a) Object.prototype (whose own prototype is null)
b) Function.prototype
c) The global window object
d) The V8 engine root
Correct Answer: a) Object.prototype (whose own prototype is null)
Explanation:
Object.prototype sits at the base of the standard prototype hierarchy, terminating with null.

87. Why is understanding prototypes crucial for JavaScript developers?

a) It underpins JavaScript's object model, memory sharing, inheritance mechanics, and performance optimization.
b) It is only required for writing compilers.
c) It replaces asynchronous programming callbacks.
d) It is exclusively needed for HTML DOM manipulation.
Correct Answer: a) It underpins JavaScript's object model, memory sharing, inheritance mechanics, and performance optimization.
Explanation:
Mastering prototypes provides deep insight into how JavaScript structures objects, shares memory, and handles inheritance.
← Previous: JavaScript OOP MCQs for Developer Interviews & Certification
Next →: JavaScript This Keyword & Scope MCQs
NewJavaScript DOM Manipulation MCQs

JavaScript DOM Manipulation MCQs

The Document Object Model (DOM) is a cross-platform programming interface that treats HTML and XML documents as a hierarchical tree…

By MCQs Generator
NewJavaScript This Keyword & Scope

JavaScript This Keyword & Scope MCQs

Variable scoping and declaration keywords (var, let, and const) determine where identifiers are visible and accessible within a JavaScript execution…

By MCQs Generator
NewPython Arrays MCQs

Python Arrays MCQs

Unlike many other programming languages, Python does not have a built-in static array data structure in its core syntax, instead…

By MCQs Generator