Object is a real world entity with certain properties. It is a collection of key-value pairs that specify the object.
let person = {
name: "Rohan",
age: 22
};
// Here, person is an object with two properties, name and age which specifies that person.Accessing the object properties is possible in two methods:
- Dot notation
- Bracket notation
console.log(person.name);// Dot notation
console.log(person["age"]);// Bracket notationNote
If the property to be accessed is determined during run-time, using dot notation won't do the job.
let selection = "name";
console.log(person.selection);// This doesn't work
console.log(person[selection]);// This worksprevious