-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs-obj.js
More file actions
106 lines (88 loc) · 2.75 KB
/
js-obj.js
File metadata and controls
106 lines (88 loc) · 2.75 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
const blogs = [
{ title: '10 funny example of JavaScript Array', likes: 45, },
{ title: 'Understand JavaScript Array in a new way', likes: 60, },
]
const person = {
name: 'Ayyub Iqbal',
Age: 23,
Study: 'Diploma in CST',
email: 'abuayubiqbal@gmail.com',
blogs: blogs,
hobby: ['Reading', 'Watching', 'Listening', 'Eating', 'Traveling'],
action() {
console.log(this);
console.log('------------------------');
this.hobby.forEach(hobby => console.log(`${this.name} is ${hobby} and his age is ${this.Age}`))
console.log('------------------------');
},
logBlogs() {
console.log('------------------------');
this.blogs.forEach((blog) => {
console.log(blog.title, blog.likes);
})
console.log('------------------------');
}
}
// object method
person.action()
person.logBlogs()
// global this
console.log('------------------------');
console.log('Global or Window object,', this);
console.log('------------------------');
// String method
const name1 = 'ayyub iqbal';
console.log(` ---------- ${name1.toUpperCase()} ---------- `);
// update property / element
// dot notation
person.Age = 25;
// bracket notation
person['name'] = 'Abu Ayub MD Iqbal';
// add new property
const education = 'Diploma in Computer Science and Technology';
person['education'] = education;
// person['education'] = 'Diploma in Computer Science and Technology';
// delete element
delete person.Study;
console.log('------------------------');
console.log(person);
console.log('------------------------');
console.log('person is an', typeof person);
console.log('------------------------');
// --------------------
const numbers = {}
const x = 0;
const y = 1;
numbers['x'] = x;
numbers['y'] = y;
console.log(numbers);
console.log('------------------------');
// Math Objects
console.log(Math);
console.log(Math.PI);
console.log(Math.E);
console.log('------------------------');
const area = 7.5;
// Math object method
console.log(Math.round(area));
console.log(Math.floor(area));
console.log(Math.ceil(area));
console.log(Math.trunc(area));
console.log('------------------------');
const random = Math.random();
console.log(random);
console.log(Math.round(random));
console.log(Math.round(random * 100));
console.log('------------------------');
// Primitive value
let scoreOne = 100;
let scoreTwo = scoreOne;
console.log(`scoreOne ${scoreOne}, scoreTwo ${scoreTwo}`);
scoreOne = 200;
console.log(`scoreOne ${scoreOne}, scoreTwo ${scoreTwo}`);
// reference value
const userOne = { name: 'Ayyub Iqbal', age: 23 };
const userTwo = userOne;
console.log(`UserOne name ${userOne.name}, userTwo name ${userTwo.name}`);
userOne.name = 'Mahfuz';
console.log(`UserOne name ${userOne.name}, userTwo name ${userTwo.name}`);