-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjects.js
55 lines (50 loc) · 1.18 KB
/
objects.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
48
49
50
51
52
53
54
55
// Literal Object Notation
const person = {
firstName : 'Alaa',
'last name': 'Duridi',
age : '20',
hobbies : ['reading', 'games', 'coding'],
greet : function(){
console.log('Hello Every One') ;
},
score : {
maths : 90 ,
science : 80 ,
calcAvg : function () {
let avg = (90+80)/2 ;
console.log(avg) ;
return avg ;
}
},
address: null
};
console.log(person);
console.log(person['last name']) ;
console.log(person.age);
console.log(person.hobbies[0]) ;
console.log(person.score.maths) ;
person.greet() ;
person.score.calcAvg() ;
// Object() constructor
const person2 = new Object({
firstName : 'Alaa',
'last name': 'Duridi',
age : '20',
hobbies : ['reading', 'games', 'coding'],
greet : function(){
console.log('Hello Every One') ;
},
score : {
maths : 90 ,
science : 80 ,
calcAvg : function () {
let avg = (90+80)/2 ;
console.log(avg) ;
return avg ;
}
},
address: null
});
console.log(person2);
if(typeof person2 ==='object')
console.log('person2 is object');