𝗖𝗥𝗨𝗗 𝗮𝗻𝗱 𝗖𝗼𝗻𝘀𝘁𝗿𝘂𝗰𝘁𝗼𝗿𝘀 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁
You need to manage data in JavaScript. You do this through CRUD operations and constructors.
CRUD stands for Create, Read, Update, and Delete. These four steps let you manage object data.
• Create: Add new properties to an object. Use dot notation for simple keys. Use bracket notation if your key has spaces or special characters.
• Read: Get values from an object. If the key does not exist, JavaScript returns undefined.
• Update: Change an existing value. You can change it directly or use the spread operator to make a new object with updates.
• Delete: Use the delete operator to remove a property. This removes both the key and the value.
Constructors help you build objects. A constructor is a special function. It runs when you use the new keyword.
When you call a constructor, three things happen:
- JavaScript creates a new empty object.
- The this keyword points to that new object.
- The constructor returns the new object.
You should use object literals for single objects. Use constructors when you need to create many objects. Each object from a constructor stays unique. Changes to one object do not affect others.
Source: https://dev.to/karthick_07/understanding-constructors-and-crud-operations-in-programming-20pe