🔹 1. What is an object in JavaScript?
An object is a collection of key-value pairs used to store related data and functionality.
Example:
const user = { name: "Alice", age: 25 };🔹 2. How do you access object properties?
Using dot or bracket notation:
user.name // "Alice"
user["age"] // 25
🔹 3. How can you loop through an object?
Use for...in or Object.keys()/Object.entries():
for (let key in user) { console.log(key, user[key]); }🔹 4. Difference between Object.freeze() and Object.seal()?
⦁ freeze() prevents any change (no adding, deleting, or modifying properties).
⦁ seal() allows value changes, but not adding/removing keys.
🔹 5. How do you clone an object?
const clone = {...user };
// or
const copy = Object.assign({}, user);🔹 6. What is this inside an object?
this refers to the object itself in method context.
const person = {
name: "Bob",
greet() { return `Hi, I’m ${this.name}`; }
};🔹 7. How do prototypes relate to objects?
Every JS object has a hidden [[Prototype]]. It lets objects inherit properties from others.
🔹 8. What is a constructor function?
A function used to create multiple similar objects:
function User(name) {
this.name = name;
}
const u = new User("Tom");🔹 9. What's the difference between Object.create() and new keyword?
⦁ Object.create(proto) creates an object with the given prototype.
⦁ new invokes a constructor function to initialize objects.
🔹 10. How do you check if a property exists in an object?
"name" in user // true user.hasOwnProperty("age") // true💬 Tap ❤️ for more!
💎 @Htmlcss_channels | #css #JavaScript #HTML #interview