JavaScript Interview Question #26
What is an object in JavaScript?
Objects, Arrays & Core Data Handling Junior Beginner
Quick Interview Answer
An object is a collection of key-value pairs used to represent related data and behavior. Property keys are strings or symbols, while values can be any JavaScript value, including functions and other objects.
Detailed Explanation
An object is a collection of key-value pairs used to represent related data and behavior. Property keys are strings or symbols, while values can be any JavaScript value, including functions and other objects.
Objects are fundamental to JavaScript. They are commonly used for application models, configuration, API data, and structured state.
Code Example
const user = {
id: 1,
name: "Asif",
isActive: true,
greet() {
return `Hello ${this.name}`;
}
};
console.log(user.name);
console.log(user.greet());