Questions
5 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.
05 / 32

What are the key differences between javascript’s Object-based Inheritance and Conventional Class-based Inheritance?

  1. 1

    Classical inheritance is based on a strict class hierarchy with clear parent-child relationships. Prototypal inheritance is more flexible and allows for more dynamic and ad-hoc object relationships.

  2. 2

    Classical inheritance involves creating instances of predefined classes. Prototypal inheritance involves cloning or extending existing objects to create new objects.

  3. 3

    Classical inheritance can be less flexible due to the rigid class hierarchy and compilation-time definitions. Prototypal inheritance offers greater flexibility and adaptability, allowing objects to be easily modified and extended at runtime.

  4. 4

    In conventional inheritance, changing a base class can break an entire hierarchy because the structure is so rigid. In JavaScript, because it is Delegation-based, you can swap prototypes or augment them dynamically, making the code more 'composed' and flexible.

Difficulty: 5/10
Topics: prototype chain, ES6 class syntax, inheritance patterns

Scenario Questions

0-2 years experience
  1. 1

    If you need to create a simple 'Car' object that shares a 'drive' method with all instances, would you use a constructor function with prototype or an ES6 class? Walk me through the steps.

  2. 2

    What happens when you assign a property directly on an object versus on its prototype? How does that affect instances created later?

2-5 years experience
  1. 1

    We have a codebase that mixes prototype inheritance and ES6 class syntax, and a bug appears where a subclass method doesn't override the parent. How would you debug it and what inheritance differences might be causing the issue?

  2. 2

    When adding a new feature, you need to extend a third‑party library that provides a prototype‑based API, but your team prefers class syntax. What trade‑offs would you consider and how would you implement the extension?

5-8 years experience
  1. 1

    Our front‑end framework creates thousands of component instances per page. Discuss the performance implications of using prototype‑based inheritance versus class‑based inheritance for these components.

  2. 2

    Design a module that abstracts over both prototype and class inheritance so that other teams can use whichever style they prefer without breaking. What edge cases would you handle?

8+ years experience
  1. 1

    We are planning a migration of a large legacy codebase that heavily uses prototype inheritance to modern ES6 class syntax. How would you approach the migration to minimize risk and ensure cross‑team consistency?

  2. 2

    From an architectural standpoint, what are the long‑term maintenance considerations when choosing prototype‑based inheritance over class‑based inheritance in a shared library used across multiple products?

Follow-up Questions

  • Can you give an example where prototype inheritance offers an advantage over class syntax?
  • How does the 'super' keyword work under the hood in ES6 classes?
  • What impact does this have on tooling like linters or type systems?