When storing details about something, like a car, we can use separate variables for each piece of information.
This approach works for a few details but quickly becomes messy and hard to manage as the number of variables grows, especially if we also need to store additional features like the car's color or seating capacity.
Instead of using multiple variables, we can group related details together using an object
. Here is how we can represent the same car details using an object.
An object can have multiple properties, where each property consists of a key
and a value
, separated by commas. In this example, the model
property stores the car's model year, 2011 and the fuelType property stores the type of fuel the car uses, petrol.
By grouping related data into an object, we make the code easier read and maintain, especially as the number of details increases.