-
Notifications
You must be signed in to change notification settings - Fork 0
/
day24.html
64 lines (47 loc) · 1.72 KB
/
day24.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
<!-- Async Await function in Js -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Async Await In javasrcipt</title>
</head>
<body>
<h1>Async await in Javasrcipt</h1>
<!-- A function can be made async by using async keyword like this
asyn function get(){
return 7;
}
hum kisi bhi function ko async bana skte hai aur uske andar promise ko await kr skte hai
alag alag async function simulataneously execute hote hai like there is async function "lokesh" in our code if we have another async function "mukesh" then lokesh and mukesh executes simultaneously
-->
<script>
async function lokesh() {
let delhiWeather = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("27 Deg");
}, 1000);
});
let bangloreWeather = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("25 Deg");
},7000);
});
// delhiWeather.then(alert);
// bangloreWeather.then(alert);
console.log("Fetching delhi weather please wait")
let delhi = await delhiWeather;
console.log("Fecthed Delhi weather "+ delhi);
console.log("Fetching Banglore weather please wait")
let banglore = await bangloreWeather;
console.log("Fecthed Banglore weather "+ banglore);
return [delhi,banglore];
} // if we remove asyn from a function then that will show error
console.log("Welcome to weather Department");
let a = lokesh()
a.then((value)=>{
console.log(value);
})
</script>
</body>
</html>