𝗢𝗯𝗷𝗲𝗰𝘁𝘀 𝗶𝗻 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁

JavaScript objects store data in key-value pairs. Each pair is a property. The key is a string. The value is any data type like a number, string, or function.

You create objects using object literal notation. Use curly braces to hold your data.

Creating an object:

You access properties in two ways:

  1. Dot notation Use a period between the object name and the property name. Example: person.firstName

  2. Array-like notation Use square brackets and quotes. This is necessary if your key has spaces. Example: address['building no']

Important rules:

You can change data inside an object:

To check if a property exists, use the in operator. It returns true if the key is present and false if it is not.

Example: 'employeeId' in employee returns true.

Source: https://dev.to/pdhanush26/objects-in-javascript-ma6