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

How does JavaScript handle circular references in object prototypes?

Difficulty: 7/10
prototype chain, circular reference, memory management
  1. 1

    JavaScript handles circular references in object prototypes by ensuring that properties are looked up only once during property access.

  2. 2

    Circular references can lead to infinite loops if not handled correctly, so JavaScript employs mechanisms to break such loops.

Scenario Questions

0-2 years experience

  1. 1If you create an object that sets its prototype to itself, what will happen when you try to access a property that isn’t on the object?
  2. 2Write a small snippet that creates two objects whose prototypes reference each other. What does `objA.__proto__ === objB` evaluate to, and why?

2-5 years experience

  1. 1We noticed a memory leak after adding a feature that builds a prototype chain dynamically. The chain accidentally creates a circular prototype reference. How would you detect and fix it?
  2. 2During a refactor, a colleague changed a class’s `extends` logic and now `instanceof` checks are failing. Explain how a circular prototype could cause that and what steps you’d take to debug.

5-8 years experience

  1. 1Our UI library builds component prototypes at runtime based on plugins. Some plugins can be loaded in any order, and we’ve seen occasional stack overflows when traversing the prototype chain. How would you redesign the prototype handling to avoid circular references while keeping the plugin system flexible?
  2. 2In a large codebase we need to serialize objects that may contain prototype cycles for caching. Discuss the trade‑offs of using `JSON.stringify` with a replacer versus a custom serializer that respects prototype links.

8+ years experience

  1. 1We are migrating a legacy monolith that heavily relies on prototype inheritance to a modern ES6 class architecture across multiple teams. Some modules have hidden circular prototype links that cause subtle bugs in production. How would you plan a migration strategy that identifies and eliminates these cycles without breaking existing contracts?
  2. 2Our company wants to expose a sandboxed scripting environment to third‑party developers. The sandbox must prevent prototype‑pollution attacks, including circular prototype chains that could cause infinite lookups. What architectural safeguards would you put in place at the runtime and API level?

Follow-up Questions

  • What tools or browser APIs would you use to inspect prototype chains at runtime?
  • Can you explain how garbage collection treats objects involved in a prototype cycle?
  • How does a circular prototype affect `Object.getPrototypeOf` and `instanceof` checks?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.