-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11.object1.js
More file actions
40 lines (32 loc) · 1.09 KB
/
11.object1.js
File metadata and controls
40 lines (32 loc) · 1.09 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
// singleton
//Object.create is a constructer method and in these only singleton is formed
// object literals
const sym = Symbol("Key")
const JsUser = {
name: "Rishav",
// sym: "key", //in these output is same but differs in the type and gives string as type instead of symbol.
[sym]: "key", //the correct syntax to display symbol
"full name": "Roxx" ,
age: 19,
location: "Kerala" ,
email: "rishav@microsoft.com",
isLoggedIn: false ,
lastLoginDays: ["Monday" , "Saturday"]
}
// console.log(JsUser["email"]);
// console.log(JsUser.email);
// console.log(JsUser["full name"]);
// console.log(JsUser[sym]);
// console.log(typeof sym);
// JsUser.email = "rishav@google.com"
// Object.freeze(JsUser) // freeze the object and makes it unable to change
// JsUser.email = "rishav@amazon.com"
// console.log(JsUser)
JsUser.greeting = function(){
console.log("Hello User");
}
JsUser.greeting2 = function(){
console.log(`Hello User with name ${this["full name"]}`);
}
console.log(JsUser.greeting());
console.log(JsUser.greeting2());