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

What happens when you try to access a property that doesn't exist on an object?

Difficulty: 2/10
property access, undefined, prototype chain

If you try to access a property that doesn't exist on an object, JavaScript will traverse the prototype chain until it reaches the end. If the property is not found on any object in the prototype chain, the result will be undefined.

Scenario Questions

0-2 years experience

  1. 1If you have const user = {name: 'Alice'}; what will console.log(user.age) output and why?
  2. 2Write a one‑line snippet that safely reads a nested property like user.profile.bio without throwing an error when any part is missing.

2-5 years experience

  1. 1You’re debugging a feature where a UI component crashes because it expects data.title but the API sometimes omits title. Explain why accessing data.title results in undefined and how you’d guard against it.
  2. 2During a code review you notice a colleague wrote if (obj.prop) { … } assuming missing properties throw. How would you explain the actual behavior and suggest a more reliable check?

5-8 years experience

  1. 1Design a utility function that logs a warning the first time a missing property is accessed on a large shared object, without impacting performance. What trade‑offs do you consider?
  2. 2In a high‑traffic Node.js service, you need to validate incoming JSON payloads. How does relying on JavaScript’s undefined for missing fields affect error handling and monitoring at scale?

8+ years experience

  1. 1Your organization is migrating several microservices from loosely typed JavaScript objects to a typed schema (e.g., using TypeScript or JSON Schema). How would you approach handling existing code that frequently accesses non‑existent properties, and what architectural changes would you recommend to prevent silent undefined bugs?
  2. 2When designing a public SDK, you must decide how to surface missing optional fields to SDK consumers. Discuss the pros and cons of returning undefined versus throwing errors or using sentinel objects, considering backward compatibility and developer experience.

Follow-up Questions

  • What happens if you try to call a method on the value you just accessed?
  • How does the prototype chain influence the result of a missing property lookup?
  • Can you differentiate between undefined and a property that exists with the value undefined?
Share

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