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

How does javascript implements object oriented programming?

JavaScript is unique because it doesn't use the 'Classical' inheritance found in languages like Java or C++. Instead, it uses Prototypical Inheritance. While ES6 introduced the class keyword, it is actually syntactic sugar over JavaScript's existing prototype system. Under the hood, it’s still objects linking to other objects. Javascript uses ES6 classes, Constructor functions and prototypes to create and extend classes.

Objects can be seen as a collection of properties. There are two types of object properties:
  1. 1

    Objects in JavaScript inherit properties and methods from their prototypes.

  2. 2

    When you access a property or method on an object, if it's not found on the object itself, the JavaScript engine looks up the prototype chain until it finds the property or reaches the end of the chain.

  3. 3

    For inheritance, JavaScript only has one construct: objects. Unlike classical inheritance in other programming languages, JavaScript uses a prototype chain to achieve inheritance where objects can inherit properties and methods from other objects.

  4. 4

    All objects in JavaScript inherit from at least one other object. The object being inherited from is known as the prototype, and the inherited properties can be found in the prototype object of the constructor.

  5. 5

    Each object has a private property [[Prototype]] which holds a link to another object called its prototype. This prototype object, in turn, may have its own [[Prototype]], and so on until an object is reached with null as its prototype forming a prototype chain.

  6. 6

    By definition, null has no prototype, and acts as the final link in this prototype chain.

  7. 7

    It is possible to mutate any member of the prototype chain or even swap out the prototype at runtime, so concepts like static dispatching do not exist in JavaScript.