When to Use Objects
Objects are used to represent a “thing” in your code. That could be a name, a person, a car, a book, a table — basically anything that is made up or can be defined by a set of characteristics. In objects, these characteristics are called properties
Properties consists of a Key and a Value .
name and age are keys and, ram and 19 are Values. Combinely Termed as Properties.
Accessing Object Values
For This, You Have two ways to access the Values
- Dot (.) Representations
Bracket( [ ] ) Representation
Note : Both will Result Same.
Assigning Value to Properties
You can add new properties to an existing object by simply giving it a value.
The delete keyword deletes a property from an object:
The block of code inside of the for...in loop will be executed once for each property.
First, We have declared the Object monthlySalary and then assigned salaries of the person.
for...in loop will Iterate through all the Elements of the Object. i.e. it will print all the salaries of Persons.