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

What is the difference between an object's `__proto__` and a constructor function's `prototype` property and [[Prototype]]?

It's recommended to use standard methods like Object.getPrototypeOf() and Object.setPrototypeOf() for working with prototypes in modern JavaScript.

prototype
  1. 1

    The prototype property is used in constructor functions to define the prototype that will be used for objects created by that constructor.

  2. 2

    The prototype is an object that serves as a template for other objects. In JavaScript, every object has a prototype, and you can think of it as a set of properties and methods that can be inherited by other objects. You can define a prototype explicitly using the Object.create() method or implicitly by creating objects using a constructor function.

javascript
__proto__
  1. 1

    Pronounced dunder proto, The __proto__ property is a reference to the prototype of an object, it exposes the [[Prototype]]. If used as a getter, returns the object's [[Prototype]].

  2. 2

    While it provides a convenient way to work with prototypes, it's not part of the official ECMAScript specification and is considered non-standard, although widely supported in practice.It's important to note that its usage is discouraged in favour of more standardized methods like Object.getPrototypeOf() and Object.setPrototypeOf(). It is a deprecated property

  3. 3

    proto` is an accessor property (getter/setter) available on object instances in some JavaScript environments (such as browsers). The proto setter allows the [[Prototype]] of an object to be mutated. The value provided must be an object or null. Providing any other value will do nothing. It allows you to get and set the prototype of an object directly using dot notation.

  4. 4

    A property definition of the form proto: value or proto: value does not create a property with the name proto. Instead, if the provided value is an object or null, it points the [[Prototype]] of the created object to that value. (If the value is not an object or null, the object is not changed.)

  5. 5

    Only a single prototype setter is permitted in an object literal. Multiple prototype setters are a syntax error.

  6. 6

    Property definitions that do not use colon notation are not prototype setters. They are property definitions that behave identically to similar definitions using any other name.

javascript
[[Prototype]]` (Internal Property):
  1. 1

    [[Prototype]]` is an internal property of an object in JavaScript.

  2. 2

    It is not directly accessible in code, and you typically interact with it indirectly using methods like Object.getPrototypeOf(obj) or by setting an object's prototype when creating it.

  3. 3

    It represents the prototype of the object, which is used for property and method inheritance in the prototype chain.

  4. 4

    Modifying [[Prototype]] directly is not recommended, and it's generally better to use other methods and patterns for working with prototypes.

javascript