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

What is static dispatching in object-oriented programming?

Difficulty: 5/10
method binding, prototype inheritance, performance
  1. 1

    In object-oriented programming, static dispatching is a method dispatch that resolves a call to a method at compile time. It's a form of polymorphism that's fully resolved during compile time.

  2. 2

    Static dispatching is also known as early binding. It's the default dispatch mode when the concrete type can be determined at compile time.

  3. 3

    In contrast, dynamic dispatching, also known as run-time dispatch or late binding, defers the decision to run time. Dynamic dispatching is used when the concrete type implementing the trait is not known at compile time.

  4. 4

    Most object-oriented programming languages support dynamic dispatching because it allows polymorphism to exist.

Scenario Questions

0-2 years experience

  1. 1You have a class `Animal` with a method `speak` and a subclass `Dog` that overrides it. When you call `dog.speak()`, how does JavaScript decide which function runs, and how would using a static method change that decision?
  2. 2If you write a helper that calls `this.calculate()` inside a class, what determines at runtime which `calculate` implementation is used? Explain the difference between static and dynamic dispatch in this simple case.

2-5 years experience

  1. 1A teammate replaced an instance method with a static method on the base class to speed up a tight loop, but now subclass overrides no longer work. Walk me through why the behavior changed and how you’d fix it.
  2. 2During a refactor we introduced a generic utility in TypeScript that calls a method on a generic type. Subclasses that override the method still hit the base implementation. Why did static dispatch occur, and what can you do to preserve the override?

5-8 years experience

  1. 1We’re building a component library that allows third‑party plugins to extend core components. How would you expose core methods so they can be statically dispatched for performance while still permitting plugins to override them when needed?
  2. 2Profiling a high‑throughput Node service shows many deoptimizations due to dynamic method lookups. Propose a strategy that uses static dispatch to reduce overhead, and discuss any edge cases or limitations.

8+ years experience

  1. 1Our platform is migrating from prototype‑based inheritance to a class‑based API that relies on static dispatch to cut startup latency. What architectural steps, migration plan, and backward‑compatibility measures would you recommend?
  2. 2Multiple teams need to decide whether to expose a core utility library as static functions (static dispatch) or as instance methods (dynamic dispatch). How would you evaluate the long‑term maintenance, bundle‑size, and tree‑shaking implications of each approach?

Follow-up Questions

  • What impact does static dispatch have on tree‑shaking and bundle size?
  • Can you give an example where static dispatch would break polymorphic behavior?
  • How does V8 decide to inline a method call?
Share

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