-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsync_keyword.js
More file actions
34 lines (32 loc) · 855 Bytes
/
Async_keyword.js
File metadata and controls
34 lines (32 loc) · 855 Bytes
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
async function hello() {
return 'hey guy!';//promise will be resolved with the value 'hey guy!'
// if we dont return a value it will give us undefined value in resolved of promise
}
hello().then((data) => {
console.log("promise resolved with:", data)
})
async function uhOh() {
throw "oh no!"// if we throw an error ot wil be rejected
return 'LANLA LANLA'
}
uhOh()
.then((data) => {
console.log("PROMISE RESOLVED WITH :", data)
})
.catch((err)=>{
console.log("error caught :",err)
})
const login= async(username, password)=>{
if(!username||!password) throw 'Missing Credential'
if(password==='corgifeetarecute') return 'WELCOME!'
throw 'INVALID PASSWORD'
}
login('akjwebf','cor')
.then(msg=>{
console.log("LOGED IN!")
console.log(msg)
})
.catch(err=>{
console.log("ERROR!");
console.log(err)
})