Questions
7 of 32
1What is the constructor function?
2What are Objects?
3What are the properties of an object?
4How does javascript implements object oriented programming?
5What are the key differences between javascript’s Object-based Inheritance and Conventional Class-based Inheritance?
6What is a prototype in JavaScript?
7How we can implement prototype-based inheritance?
8Explain the prototype chain and its role in property lookup.
9What is the difference between an object's `__proto__` and a constructor function's `prototype` property and [[Prototype]]?
10What are object wrappers for primitive type?
11Can you explain the use of object wrappers with examples?
12Explain how the `instanceof` operator works.
13What are different methods to create an object?
14What is an object initializer?
15What does the `Object.create()` method do?
16How are constructor functions used to create objects with shared properties and methods?
17Show an example of ES6 classes to create objects and inherit properties?
18What are factory functions in JavaScript ?
19What are Object constructors in JavaScript ?
20How can you add new properties and methods to the prototype of an existing constructor function?
21What is prototype pollution, and how can it be a security risk in JavaScript?
22Is modifying or extending built-in object prototypes recommended (e.g., adding a method to `Array.prototype`)? Why or why not?
23What happens when you try to access a property that doesn't exist on an object?
24How can you prevent or mitigate prototype pollution vulnerabilities in your code?
25How does the `Object.prototype.hasOwnProperty()` method work?
26How can you optimize prototype chain lookup for better performance?
27Can you explain how `Object.prototype.constructor` property works?
28What is the difference between modifying the prototype of an object and adding a property directly to the object?
29How does JavaScript handle circular references in object prototypes?
30What is static dispatching in object-oriented programming?
31What is the purpose of the `Object.keys()` method?
32Write a function flattenObject(obj) that flattens a deeply nested object into a single-level object, using dot notation for nested keys.
07 / 32

How we can implement prototype-based inheritance?

To implement prototype-based inheritance in JavaScript, you essentially link one object to another so that the second object can delegate property lookups to the first.

  1. 1

    Object.create() is the most direct way to implement prototypal inheritance. It creates a new object and allows you to specify exactly which object should be its prototype.

  2. 2

    You can create a prototype-based inheritance by defining methods and properties on a prototype object and then using a constructor function to create instances that inherit from that prototype. This allows you to define shared behaviour that is available to all instances of the object.

  3. 3

    Classes make the prototype-based implementation much easier to read. Even though it looks like 'Class-based' code, JavaScript is still just setting up a prototype chain behind the scenes.

Using Object.create() (The Cleanest Way)
In this example, both `person1` and `person2` instances of the `Person` constructor share the same `sayHello` method through prototype-based inheritance.
Using ES6 Classes
Difficulty: 5/10
Topics: prototype chain, object creation, inheritance patterns

Scenario Questions

0-2 years experience
  1. 1

    We need a simple Animal constructor that other objects can inherit from using prototypes. How would you set that up so that a Dog instance can call a method defined on Animal?

  2. 2

    If you create an object with Object.create(proto) and then add a property directly on the new object, which version of that property will be accessed when you read it?

  3. 3

    After deleting a property from a prototype but not from an existing instance, what will console.log(obj.prop) output and why?

2-5 years experience
  1. 1

    You added a method to Parent.prototype after creating several Child instances. Some of the existing children see the new method, others don’t. What could cause that, and how would you fix it?

  2. 2

    While refactoring a legacy codebase, you replace a class‑style inheritance with prototype‑based inheritance. After the change, a feature that relied on instanceof starts failing. Walk me through how you would diagnose and resolve the issue.

  3. 3

    Explain the performance implications of using Object.setPrototypeOf inside a hot loop versus creating objects with the correct prototype up‑front.

5-8 years experience
  1. 1

    Our front‑end framework creates thousands of UI component objects per second. Discuss the trade‑offs between using Object.create versus a factory function that manually copies properties for inheritance, focusing on memory usage and GC pressure.

  2. 2

    We need to support a plugin system where plugins can extend core objects at runtime. How would you design the prototype chain to allow safe extension without breaking existing instances?

  3. 3

    During a production incident, you notice a memory leak traced to objects retaining references to their prototype. Explain how prototype‑based inheritance can cause such leaks and propose a mitigation strategy.

8+ years experience
  1. 1

    Our monorepo contains multiple services written in JavaScript, some using ES6 classes and others using prototype inheritance. We want to standardize on a single inheritance model. What factors would you consider when deciding to migrate everything to class syntax versus keeping prototype patterns, especially regarding tooling, type safety, and runtime behavior?

  2. 2

    Design a strategy for gradually deprecating a deeply nested prototype chain in a legacy library while ensuring backward compatibility for external consumers.

  3. 3

    How would you structure a shared utility library that provides base prototypes for domain objects, so that different teams can extend them without causing prototype pollution across the codebase?

Follow-up Questions

  • What happens if you overwrite a prototype method after instances are created?
  • How would you avoid accidental prototype pollution in a shared library?
  • Can you sketch a quick code example that shows the lookup order for a property?