-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
116 lines (98 loc) · 2.59 KB
/
index.js
File metadata and controls
116 lines (98 loc) · 2.59 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
107
108
109
110
111
112
113
114
115
116
const name = "Md.Bozlur Rosid Sagor";
console.log(name);
let something = "I know somethig about....";
console.log(something);
something = "He knows something about ....";
console.log(something);
console.log(something.length);
/*
Here JavaScript ES6 `const` value not change
But you may `let` value change one more
*/
const username = "mbr-sagor";
const age = 25;
console.log(`Hey there my username is ${username} and my age is ${age}`);
const books = ['Java', 'Python', 'JavaScript'];
books.forEach((book, index) => {
console.log(`${index}. ${book}`);
})
console.log("\n");
// map
const bookList = books.map(item => {
console.log(item)
})
bookList;
// Filter
const bookFilter = books.filter(item => {
return item === 'Java';
})
console.log(bookFilter);
// Function
function getNews(title, author) {
return {
title, author
};
}
var news = getNews("Learn JavaScript ES6 with mbr-sagor", "Md.Bozlur Rosid Sagor");
console.log(news);
console.log(typeof news);
// Arrow function
const location = (area) => {
console.log(`Right now I am at ${area}`);
}
location('Dhaka-Bangladesh');
// function add default value
const add = (a=10, b=20) => {
console.log(a + b);
}
add(3);
// Object
const user = {
name: "Mbr-Sagor",
first_name: "Md.Bozlur Rosid",
last_name: "sagor",
age: 25,
study: "CSE",
sayName: function () {
console.log(`My Name is ${this.name} age ${this.age} and I am study in ${this.study}`);
const full_name = () => {
console.log(`Frist Name: ${this.first_name} and Last Name: ${this.last_name}`);
};
full_name();
},
};
user.sayName();
// How to use class
class Man{
constructor(username, password) {
this.username = username;
this.password = password;
}
access() {
console.log(`Username: ${this.username} and Password: ${this.password}`);
}
}
const man = new Man('sagor', 'sagor123');
man.access();
class Woman extends Man{
constructor(username, password, email) {
super(username, password);
this.email = email;
}
access() {
console.log(`Email: ${this.email}`);
}
}
const woman = new Woman('something', 'something123', 'mbrsagor@gmail.com');
woman.access();
//
const prom = new Promise((resolve, reject) => {
// Here is async
setTimeout(() => {
resolve({ 'title': 'Another new post.', 'content': 'Hello there, I am sagor start-up software developer.', 'author': 'mbr-sagor' });
reject(new Error('Something went wrong'));
}, 2000);
});
prom.then(data => {
console.log(data);
}).catch(err => console.log(err));