In JavaScript, objects are king. If you understand objects, you understand JavaScript.
Objects in JavaScript helps us to hold data in a key:value pairs.
Syntax:
const obj = {
key: value;
}
We have learned how to declare variable like,
const firstName = 'Kaarthik';
const lastName = 'Sekar';
const birthYear = 2001;
Objects are variables too. But objects can contain many values.
const kaarthik = {
firstName: "kaarthik",
lastName: "sekar",
birthYear: 2001,
currentStatus: "commited",
favCountries: ["France", "Switzerland", "Venice"]
}
console.log(kaarthik);
We can access object values through dot notations.
console.log(kaarthik.birthYear); // 2001
console.log(kaarthik.firstName); // Kaarthik