In JavaScript, an object is a collection of key-value pairs, where the keys (properties) are strings and the values can be of any data type (strings, numbers, arrays, functions, etc.). Objects allow you to store and organize data efficiently.
Objects can be created in multiple ways:
let person = {
name: "Alice",
age: 25,
isStudent: true
};
console.log(person.name); // Output: Alice
console.log(person.age); // Output: 25
console.log(person.isStudent); // Output: true
new Object()
(Less Common)let person = new Object();
person.name = "Alice";
person.age = 25;
console.log(person.name); // Output: Alice
You can access object properties in two ways:
console.log(person.name); // Dot notation → Output: Alice
console.log(person["age"]); // Bracket notation → Output: 25
💡 Use bracket notation when property names have spaces or special characters.