While learning JavaScript objects, I practiced a simple concept that appears everywhere in software development: CRUD.
CRUD stands for:
Create → Add data
Read → Access data
Update → Change data
Delete → Remove data
Let's use a vehicle object as an example.
const vehicle = {
model: "KTM 350",
price: 200000,
fuelType: "Fuel",
cc: 350,
drive: function() {
console.log("Speed: 150 km/h");
}
};
1.Create
Add a new property:
vehicle.gear = 6;
2.Read
Access existing data:
console.log(vehicle.model);
console.log(vehicle.price);
We can also call a method:
vehicle.drive();
3.Update
Change an existing value:
vehicle.price = 210000;
4.Delete
Remove a property:Use delete key word
delete vehicle.cc;
Now the cc property no longer exists.
The basic idea
Create → vehicle.gear = 6
Read → vehicle.model
Update → vehicle.price = 210000
Delete → delete vehicle.cc
This simple example helped me understand that CRUD isn't only related to databases or APIs.
The same four operations can be practiced directly with JavaScript objects.
I'm building my JavaScript fundamentals one concept at a time.
Top comments (0)