DEV Community

Abinaya V
Abinaya V

Posted on

Objects in JavaScript

object means:

   In JavaScript, an object is a data type used to store multiple values in one variable. These values are stored as key–value pairs.
Enter fullscreen mode Exit fullscreen mode

Think of an object like a real-world object.

**For example, a car has:**
   -color
   -brand
   -model
Enter fullscreen mode Exit fullscreen mode

In JavaScript, that looks like this:

Here:
car → the object
color, brand, model → keys (also called properties)
"red", "Toyota", "Corolla" → values

CRUD means:

C → Create
R → Read
U → Update
D → Delete

1. CREATE (Add new data)

student.mark = 85;
console.log(student);
output
{ name: "Abi", age: 20, course: "JavaScript", mark: 85 }

2. READ (Get data)

console.log(student.name);       // Abi
console.log(student["course"]);  
Enter fullscreen mode Exit fullscreen mode

3. UPDATE (Modify data)

 student.age = 21;
 console.log(student.age); // 21
Enter fullscreen mode Exit fullscreen mode

4. DELETE (Remove data)

 delete student.course;
 console.log(student);
Enter fullscreen mode Exit fullscreen mode

output
{ name: "Abi", age: 21, mark: 90 }

Top comments (0)