-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava-objects.js
More file actions
49 lines (45 loc) · 1.11 KB
/
Copy pathjava-objects.js
File metadata and controls
49 lines (45 loc) · 1.11 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
console.log("Objects in JavaScript");
console.log();
const mySym = Symbol("key");
// object literals
const JSUser = {
name: "Palika",
age: 67,
[mySym]: "mykey",
location: "Patiala",
email: "PalikaChopra@thapar.edu",
isLoggedin: false,
};
//Object.create() -> can create singleton objects.
JSUser.email = "Palika@thapar.edu";
//Object.freeze(JSUser): freezes user, changes are not propogated.
JSUser.greeting = function () {
console.log(`Hello There ${this.name}`);
};
//console.log(JSUser.greeting());
// how to merge two objects
const obj1 = {
1: "a",
2: "b",
3: "c",
};
const obj2 = {
4: "d",
5: "e",
};
const obj3 = Object.assign({}, obj1, obj2); //merges objects
//console.log(obj3);
//another way (spread)
const obj67 = {...obj1,...obj2} // same result
//console.log(Object.keys(JSUser)) // returns array of keys
//console.log(JSUser.hasOwnProperty('IsLoggedin')); //returns true or false
const {name: n} = JSUser //new name for name in JSUser
console.log(n);
/* APIS
menu at a restaurant = API Documentation
json = {
"name": "Joanne",
"price": "120",
"coursename": "JS in Spanish"
}
*/