JavaScript Object Interview Questions and Answers
What is an object in JavaScript?
An object is a collection of key-value pairs where keys are property names (strings or symbols), and
values can be any type of data, including other objects or functions.
How do you create an object in JavaScript?
You can create an object using:
1. Object literals: `const obj = { key: value };`
2. The `Object` constructor: `const obj = new Object();`
3. `Object.create()` method: `const obj = Object.create(proto);`
What is the difference between an object and an array in JavaScript?
An object stores unordered key-value pairs, while an array stores ordered data indexed numerically.
How can you access the properties of an object?
Using dot notation (e.g., `obj.key`) or bracket notation (e.g., `obj['key']`).
What is the prototype chain?
The prototype chain is a mechanism in JavaScript where objects inherit properties and methods
from other objects (prototypes).