-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19-Objects.js
More file actions
33 lines (25 loc) · 756 Bytes
/
Copy path19-Objects.js
File metadata and controls
33 lines (25 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Objects are of reference type
// Arrays are not sufficient to work with real world objects so objects came to rescue
// Objects dont have index
// They use key value pairs
// declaring an object
const person = {
name: "Vaishnao",
age: 21,
hobbies: ["Reading", "Football", "Design"],
};
// Accessing objects
// using . notation
console.log(person.name);
console.log(person.age);
console.log(person.hobbies);
// using [] notation
console.log(person["name"]); // Remember to use "" for the key as js bydefault stores them as strings
console.log(person["age"]);
console.log(person["hobbies"]);
// Adding elements to objects
// using . notation
// person.gender = "male";
// using [] notation
// person["gender"] = "male";
console.log(person);