4. Use Cases of Objects
Objects are invaluable for storing related data in a structured manner. Consider the scenario of managing user information. Instead of using separate variables for each user attribute, objects provide a more organized approach.
Without Object:
let employee1Name = "Alice";
let employee1Surname = "Smith";
let employee1Age = 35;
let employee1Email = "alice.smith@example.com";
let employee2Name = "Bob";
let employee2Surname = "Johnson";
let employee2Age = 28;
let employee2Email = "bob.johnson@example.com";
With Object:
let employee1 = {
firstName: "Alice",
lastName: "Smith",
age: 35,
email: "alice.smith@example.com"
};
let employee2 = {
firstName: "Bob",
lastName: "Johnson",
age: 28,
email: "bob.johnson@example.com"
};