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

What is an object initializer?

Difficulty: 3/10
object literals, property shorthand, spread syntax
  1. 1

    An object initializer is a comma-delimited list of key value pairs, enclosed in curly braces ({}).

  2. 2

    More commonly known as Object Literal notation

  3. 3

    Instead of using a constructor or a class, you literally 'initialize' the object by describing it.

It is the most common and simplest way to create a JavaScript object. In its simplest form, it consists of key: value pairs.
Enhanced Object Literals (ES6+)
  1. 1

    If the variable name matches the property key, you can omit the value.

  2. 2

    You can skip the function keyword and the colon when defining methods.

  3. 3

    You can use square brackets inside the literal to use a dynamic expression or variable as a key.

ES6+ usage examples:

Scenario Questions

0-2 years experience

  1. 1How would you create a new user object with `name` and `email` properties using an object initializer?
  2. 2Given variables `firstName` and `lastName`, show how to build an object that automatically uses those variable names as property keys.
  3. 3What will the object look like after executing `const obj = {a: 1, a: 2};` and why?

2-5 years experience

  1. 1You need to merge default settings with a response from an API. Walk me through how you'd use an object initializer and spread syntax to build the final config, and what pitfalls you’d watch for.
  2. 2A teammate added a new field to a request payload, but the server receives `undefined`. The code uses a computed property name inside an object initializer. How would you debug the issue?
  3. 3Explain why spreading an object into another initializer (`{...base, id: 5}`) can unintentionally overwrite properties, and how you'd guard against that in a larger codebase.

5-8 years experience

  1. 1Our front‑end team shares a UI theme object built from several modules. How would you design its initialization to ensure immutability and avoid circular references when the app scales?
  2. 2When serializing objects for storage we need to strip functions and prototype methods. Show how you'd use an object initializer to create a plain data snapshot, and discuss performance considerations for millions of records.
  3. 3We are refactoring a legacy codebase that constructs objects via constructor functions. What are the trade‑offs of converting those to plain object initializers, especially regarding prototype inheritance and memory usage?

8+ years experience

  1. 1Our organization is moving from a monolithic config file to a distributed, version‑controlled configuration service. How would you redesign component configuration creation using object initializers to support lazy loading and backward compatibility?
  2. 2Across several microservices we need a consistent shape for request payloads. Describe how you'd establish a shared library that defines these shapes with object initializers, and how you'd evolve them without breaking existing services.
  3. 3When migrating a large codebase to TypeScript, how would you leverage object initializer patterns to enforce type safety while minimizing churn, and what architectural guidelines would you set for future developers?

Follow-up Questions

  • Can you write a short snippet that demonstrates property shorthand and a computed property?
  • What happens if two properties have the same key in the same initializer?
  • How would you test that the initializer produced the expected shape?
Share

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