
Objects in JavaScript
In many programs, we need to represent real-world entities such as a person, a student, a product, or a car. These entities often have multiple related properties . JavaScript provides objects to organize this type of data in a clear and structured way. What Are Objects and Why Do We Need Them? An object is a data structure that stores information as key-value pairs . Each piece of data has: a key (also called a property name) a value (the data stored in that property) Example: let person = { name : " Alice " , age : 25 , city : " London " }; Here: Key Value name "Alice" age 25 city "London" Objects help us: Represent real-world data Organize related information together Access and update data easily Array vs Object It is helpful to understand the difference between arrays and objects . Array Arrays store ordered values and are accessed using indexes . let fruits = [ " Apple " , " Banana " , " Mango " ]; console . log ( fruits [ 0 ]); // Apple Object Objects store named values and are
Continue reading on Dev.to Webdev
Opens in a new tab



