-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectsex1.js
48 lines (39 loc) · 1.22 KB
/
Objectsex1.js
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
//Singleton : when we create objects using new keyword then it will be a singleton
//when we create object direclty using literals then it is not singleton
//Singleton
//object.create()
//object literals
const mysym=Symbol("Key1")
const juser={
name:"Akshay",
"fullname":"Akshay Anand",
[mysym]:"symbol1",
age:22,
location:"location",
isloggedin:false,
lastlogindays:["Monday","Saturday"]
}
//first way of accessing members
// console.log(juser.email);
// //second way of accessing members
// console.log(juser["email"]);
// console.log(juser["fullname"]);
// console.log(juser[mysym]);
//overwriting the content of the object
// juser.email="[email protected]"
// console.log(juser.email);
// //we can freez our object so that it will now not accept any changes
// Object.freeze(juser)
// juser.email="[email protected]"
// console.log(juser.email);
// //console.log(juser);
//adding function to the object
juser.greeeting=function(){
console.log("Hello js user");
}
juser.greetingtwo=function(){
console.log(`hello js user, ${this.name} and my age is ${this.age}`);
}
console.log(juser.greeeting());
console.log(juser.greetingtwo());