-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
173 lines (140 loc) · 5.74 KB
/
index.html
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced JS</title>
</head>
<body>
<h1>Advanced JavaScript</h1>
<script>
// for of (loop)
let score = [80, 50, "shubham"]; // YOU CAN PASS ANYTHING INSIDE ARRAY NUMBER/STRING
for (let x of score) // FOR OF ALLOW YOU TO ITERATE OVER ITERABLE OBJECTS
{
console.log(x);
}
// tEMPLATE LITERALS
//. FIRST POINT- HERE YOU CAN USE BACKTICK (TEMPLATE LITERALS)
// for multiple line string we use template literal
// for example
let str = `
hello
world`;
console.log(str);
let str1 = " shubham";
console.log(`my name is ${str1}.`);
//--------------------------------------------------------------------------------------------------------------------------------------
//ARRAY DESTRUCTURING
// it is an efficient way to extract multiple values from data that is stored in arrays or objects.
let book = ["book", 200, 300];
let [name, page, price] = book;
console.log(price);
//ARROW FUNCTION
// it allow you to create functions in a cleaner way compared to regular functions.
let hello = () => console.log("hello");
hello(); // function call
//OBJECTS LITERALS
let name1 = "shubham belwal";
let course = "B.tech";
let interest = "web development";
var obj = {
name,
course,
interest,
};
console.log(obj);
/*OOP (object Oriented programming) ES6 version
you can reuse code again and again easily
class - blueprint of object .
object - real world entity.
example car = class (having properties and methods)
maruti , toyota fortuner = objects */
class Hello {
message() {
console.log("hello everyone");
}
}
let a = new Hello(); // here we make a object of class Hello
// a is a object of class Hello
a.message(); // with help of object we can access members and methods inside class.
// three types of method:
/* 1.constructor
2. prototype
3.static
constructor - used tpo initilize the object . it call automatically by just creating object.
static - we can call static method without making object .
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/
// MODULES
// with the help of modules you can use any function , variables , classes of one file to into other file.
/* we have two function inside modules
1.export
2.import
*/
/*------------------------------------------------------------------------------------------------------------------------------------------------*/
// PROMISES
// promise is a function takes some function which also take two more function resolve and reject.
// we check condition under promises and it tells us condtion will fulfill or not and then other things using then and catch
function prom(complete) {
return new Promise(function(resolve, reject) {
console.log("fetchind data,please wait.")
if (complete) {
resolve("I am successful");
} else {
reject("I am failed");
}
});
}
let onfulfilment = (result) => {
console.log(result);
}
let onrejection = (error) => {
console.log(error);
}
prom(true).then(onfulfilment);
prom(true).catch(onrejection);
/*---------------------------------------------------------------------------------------------------------------------------------------------------------------*/
//Promise.all()
// if we have lots of promise function then it is difficult to write then catch again and again so to avoid that problem we have promise.all function
// if all promise function resolve then only then function use if one of them will reject then we use catch and show error massage
let p1 = new Promise((resolve, reject) => {
setTimeout(() => {
console.log('first promise has resolved');
resolve(10);
}, 1 * 1000);
});
let p2 = new Promise((resolve, reject) => {
setTimeout(() => {
console.log('second promise has resolved');
resolve(20);
}, 2 * 1000);
});
let p3 = new Promise((resolve, reject) => {
setTimeout(() => {
console.log('third promise has resolved');
resolve(30);
}, 3 * 1000);
});
var total = 0;
Promise.all([p1, p2, p3]).then((result) => {
for (var i in result) {
total += result[i];
}
console.log(`results: ${result}`);
console.log(`Total: ${total}`);
}).catch((error) => {
console.log(`results: ${error}`);
});
/*------------------------------------------------------------------------------------------------------------------------------------*/
// AJAX
/* A - Asynchronpus
j - JavaScript
A - and
x - XML
AJAX is a technique for creating fast and dynamic web pages.
*/
</script>
</body>
</html>