Back to articles
Understanding Objects in JavaScript

Understanding Objects in JavaScript

via Dev.to Beginnerssanjeev singh

You already know how to store a single value in a variable — const name = "Alice" . But what if you need to store everything about Alice in one place — her name, age, and city? That's exactly what objects are for. An object is a collection of related data , grouped together under one name using key-value pairs . What Is an Object? Think of an object like a contact card in your phone. One card holds multiple pieces of information about one person: ┌─────────────────────────────┐ │ name → "Alice" │ │ age → 25 │ │ city → "Mumbai" │ └─────────────────────────────┘ Each piece of information has a key (like name ) and a value (like "Alice" ). Together, they form a key-value pair. Creating an Object Use curly braces {} with key: value pairs separated by commas: const person = { name : " Alice " , age : 25 , city : " Mumbai " }; name , age , city are the keys (also called properties ) "Alice" , 25 , "Mumbai" are the values Values can be any data type — string, number, boolean, array, even anot

Continue reading on Dev.to Beginners

Opens in a new tab

Read Full Article
7 views

Related Articles