-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path49 promises.js
More file actions
50 lines (44 loc) · 888 Bytes
/
49 promises.js
File metadata and controls
50 lines (44 loc) · 888 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
JavaScript Promise Object
A JavaScript Promise object contains both the producing code and calls to the consuming code:
*/
let condition=true;
let mypromise= new Promise((resolve,rejected)=>{
if(condition==true){
resolve("true");
}
else
{
rejected("false");
}
});
//method 1
mypromise.then((value)=>{
console.log(value);
}).catch((err)=>{
console.log(err);
})
// method 2
let mypromise_2=new Promise(function (resolce,rejected) {
let x=1;
if(x!=0)
{
resolce("x=0");
}
else
{
rejected("x!=0");
}
})
mypromise_2.then(function(params) {
console.log("value of ",params);
}).catch(function (params) {
console.log("i am catch function",params);
});
let mypromise__3=new Promise((resolve,rejected)=>{
setTimeout(()=>{resolve("resolve")
},3000);
});
mypromise__3.then((value)=>{
console.log(value);
}).catch((value)=>console.log(value));