Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 31f173f

Browse files
Creating and modifying objects
1 parent 62c35ae commit 31f173f

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

‎8_Objects_in_detail/object.js‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// object is an unordered collection
2+
// of related date in form of
3+
// key value pair
4+
5+
// const person = {
6+
// firstName: "Shubham",
7+
// lastName: "Kadam",
8+
// age: 23,
9+
// car: {
10+
// brand: "Mercedes",
11+
// year: 2020,
12+
// },
13+
// };
14+
15+
// console.log(person);
16+
17+
// Dot notation
18+
const person = {
19+
firstName: "Shubham",
20+
};
21+
22+
person.dog = {
23+
name: "fluffy",
24+
age: 2,
25+
};
26+
27+
person.age = 23;
28+
console.log(person.dog.age);
29+
30+
// Square bracket notation
31+
const property = "age";
32+
33+
console.log(person[property]);

‎8_Objects_in_detail/objects.md‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## Objects in detail
2+
3+
#### Creating an Object
4+
5+
```js
6+
// object is an unordered collection
7+
// of related date in form of
8+
// key value pair
9+
10+
const person = {
11+
firstName: "Shubham",
12+
lastName: "Kadam",
13+
age: 23,
14+
car: {
15+
brand: "Mercedes",
16+
year: 2020,
17+
},
18+
};
19+
```
20+
21+
#### The Dot and Square Notation
22+
23+
```
24+
// Dot notation
25+
const person = {
26+
firstName: "Shubham",
27+
};
28+
29+
person.dog = {
30+
name: "fluffy",
31+
age: 2,
32+
};
33+
34+
person.age = 23; // Age is being added in person object
35+
console.log(person.dog.age); // 2
36+
37+
// Square bracket notation
38+
const property = "age";
39+
40+
console.log(person[property]); // 23
41+
```
42+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /