Object
Object
Key Value
firstName Rahul
lastName Attuluri
age 28
city Delhi
1. Creating an Object
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
4 age: 28,
5 };
6
7 console.log(person); // O
1.1 Identifiers
Valid Identifiers:
JAVASCRIPT
1 firstName;
2 $firstName;
3 firstName;
https://learning.ccbp.in/course?c_id=5e93210e-f183-433d-a12d-79d81deb01be&t_id=79fb8730-bdad-4ef8-a1ea-7e79d207fd8b&s_id=2a65b1b9-f… 1/7
8/30/23, 6:51 AM Revolutionizing the Job Market | NxtWave
3 _firstName;
4 firstName12;
Invalid Identifiers:
JAVASCRIPT
1 12firstName;
2 firstName 12;
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
4 age: 28,
5 "1": "value1",
6 "my choice": "value2",
7 };
8
9 console.log(person); // O
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
4 age: 28,
5 "1": "value1",
6 "my choice": "value2",
7 };
8
9 console.log(person.firstNa
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
4 age: 28,
5 "1": "value1",
6 "my choice": "value2",
https://learning.ccbp.in/course?c_id=5e93210e-f183-433d-a12d-79d81deb01be&t_id=79fb8730-bdad-4ef8-a1ea-7e79d207fd8b&s_id=2a65b1b9-f… 2/7
8/30/23, 6:51 AM Revolutionizing the Job Market | NxtWave
7 };
8
9 console.log(person["firstN
Dot Notation:
JAVASCRIPT
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
4 age: 28,
5 "1": "value1",
6 "my choice": "value2",
7 };
8
9 console.log(person.gender)
Bracket Notation:
JAVASCRIPT
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
4 age: 28,
5 "1": "value1",
6 "my choice": "value2",
7 };
8
9 console.log(person["gender
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
4 age: 28,
5 };
6
7 let a = "firstName";
8
9 console.log(person[a]);
10
Expand
https://learning.ccbp.in/course?c_id=5e93210e-f183-433d-a12d-79d81deb01be&t_id=79fb8730-bdad-4ef8-a1ea-7e79d207fd8b&s_id=2a65b1b9-f… 3/7
8/30/23, 6:51 AM Revolutionizing the Job Market | NxtWave
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
4 age: 28,
5 };
6
7 let { gender, age } = p
8
9 console.log(gender); /
10
Expand
1 <!DOCTYPE html>
2 <html>
3 <head></head>
4 <body>
5 Your HTML code goes here. W
6 </body>
7 </html>
3. Modifying Objects
Dot Notation:
JAVASCRIPT
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
https://learning.ccbp.in/course?c_id=5e93210e-f183-433d-a12d-79d81deb01be&t_id=79fb8730-bdad-4ef8-a1ea-7e79d207fd8b&s_id=2a65b1b9-f… 4/7
8/30/23, 6:51 AM Revolutionizing the Job Market | NxtWave
4 age: 28,
5 };
6
7 person.firstName = "Abhi";
8
9 console.log(person.firstNa
Bracket Notation:
JAVASCRIPT
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
4 age: 28,
5 };
6
7 person["firstName"] = "Abh
8
9 console.log(person["firstN
Dot Notation:
JAVASCRIPT
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
4 age: 28,
5 };
6
7 person.gender = "Male";
8
9 console.log(person); // O
Bracket Notation:
JAVASCRIPT
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
4 age: 28,
5 };
6
7 person["gender"] = "Male";
8
9 console.log(person); // O
4. Property Value
The Value of Object Property can be
https://learning.ccbp.in/course?c_id=5e93210e-f183-433d-a12d-79d81deb01be&t_id=79fb8730-bdad-4ef8-a1ea-7e79d207fd8b&s_id=2a65b1b9-f… 5/7
8/30/23, 6:51 AM Revolutionizing the Job Market | NxtWave
Function
Array
Object
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
4 age: 28,
5 run: function () {
6 console.log("Start Ru
7 },
8 };
9
10 person.run(); // Start R
Methods:
For example, in
document.createElement(); , the
document is an Object, createElement
is a key and createElement() is a Method.
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
4 age: 28,
5 habits: ["Playing Che
6 };
7
8 console.log(person.habi
9
10 console.log(person.habi
Expand
1 let person = {
2 firstName: "Rahul",
3 lastName: "Attuluri",
4 age: 28,
5 habits: ["Playing Che
6 car: {
https://learning.ccbp.in/course?c_id=5e93210e-f183-433d-a12d-79d81deb01be&t_id=79fb8730-bdad-4ef8-a1ea-7e79d207fd8b&s_id=2a65b1b9-f… 6/7
8/30/23, 6:51 AM Revolutionizing the Job Market | NxtWave
7 name: "Audi",
8 model: "A6",
9 color: "White",
10 },
Expand
1 <!DOCTYPE html>
2 <html>
3 <head></head>
4 <body>
5 Your HTML code goes here. W
6 </body>
7 </html>
https://learning.ccbp.in/course?c_id=5e93210e-f183-433d-a12d-79d81deb01be&t_id=79fb8730-bdad-4ef8-a1ea-7e79d207fd8b&s_id=2a65b1b9-f… 7/7