-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChayeOrCode_Objects.html
More file actions
132 lines (111 loc) · 4.06 KB
/
ChayeOrCode_Objects.html
File metadata and controls
132 lines (111 loc) · 4.06 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Objects</title>
</head>
<body>
<script>
// SingleTon is nothng but tell about literlas and difference
// object constructor ( Object.create)
const mySym=Symbol("Key1") //symbol is a datatype
const JsUser ={ // Object Litrerals
name : "Shifa Rabbnai",
"age" :22,
[mySym]:"Acess a Symbol",
location:"Loralai",
emial:"Shifa@Hot.mail.com",
IsloggedIn:false,
LastLogin:["MonDay","WednesDay"]
}
console.log(JsUser) ; //retrive all object
console.log(JsUser.location); //for a specific one
console.log(JsUser["age"]);//retrive a this type of keyss
console.log( typeof JsUser[mySym]);
JsUser.emial="Shifamicrsoft@hot.com"//change in a object
console.log(JsUser);
Object.freeze(JsUser)//now we cant make chnages in our objects
location:"Balochistan"
console.log(JsUser);
// //*************** Declaring a function
JsUser.greeting= function(){
console.log("Hello js users");
}
JsUser.greeting2= function(){
console.log(`Hello js user,\n ${this.name}`);
}
console.log(JsUser.greeting());
console.log(JsUser.greeting2());
// ************************* singleton OR Not Singletone***********
const tinderUser1=new Object() //Singletone Obj
const tinderUser2= {} //no singletone obj
console.log("SingleTone Object",tinderUser1);
console.log("No singleTone object",tinderUser2);
const tinderUser= {}
tinderUser.id = "123_Abc"
tinderUser.name= "sami"
tinderUser.IsloggedIn=false
console.log(tinderUser);
const reguleruser={
email :"Some@email.com",
fullName :{
userFullName:{
firstName:"Shifa",
lastName:"Rabbani"
}
}
}
// // console.log(reguleruser.fullName.userFullName.firstName);//how to access object inside Object
// // *********************Combine objects *******************
const obj1={1:"a", 2: "b"}
const obj2={3:"a", 4: "b" ,5 : "c"}
const obj3={6:"a", 7: "h" ,8: "l"}
const obj4 = Object.assign(obj1 ,obj2, obj3)
console.log( obj4);
// *****************By Sperade operatores*************88
const obj5={... obj1,...obj2,...obj3}
console.log("Sprade Out operators", obj5);
// ******************when Values come from DataBase************
const user=[
{
id:"1",
emial:"Yahio@gamil.com"
},
{
id:"2",
emial:"Yahio@gamil.com"
},
{
id:"3",
emial:"Yahio@gamil.com"
},
]
user[1].email
console.log(tinderUser);
console.log(Object.keys(tinderUser));
console.log(Object.values(tinderUser));
console.log(Object.entries(tinderUser));//entires used for evry key appera in a array
console.log(tinderUser.hasOwnProperty("IsloggedIn"));//to check if properties are present or not
console.log(tinderUser.hasOwnProperty("email"));//to check if properties are present or not
// ***************************DE Struhuring(Used a {})******************
const course={
courseName:"JavaScript",
price:"999",
courseInstructor:"Master Shefu"
}
const {courseInstructor}= course
console.log(courseInstructor); //Or
const {courseInstructor: instructor} = course;
console.log(instructor);
// ***********************API***********************
//**************JSON:(JSON is a Js object notations ) in json keys and values both are in a string(API)*************************
// {
// " name" :"Shifa",
// " course" : "JS",
// " price" : "Free"
// }
// Also in a arry form
</script>
</body>
</html>