-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7_methods.js
64 lines (52 loc) · 1.56 KB
/
7_methods.js
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
/** PROTOTYPES :-
* prototype is a fundamental concept that is used to implement object-oriented programming.
* Every object in JavaScript is associated with a prototype object, which is an object that
* serves as a blueprint for the properties and methods that the object can have.
* These prototypes are used to create a chain of inheritance,
* allowing objects to inherit properties and methods from their prototypes.
*/
function fun() {
return new Promise( (res , rej) => {
setTimeout(() => {
rej("SUCCESS");
}, 2000);
})
}
let z = 23;
let x = fun();
console.log(x);
x
.then( (result) => {
console.log(result);
console.log("successfully returned");
console.log(x);
})
.catch( (error) => {
console.log(`${error} is not returned and z's value is , ${z}` );
console.log(x);
let alpha = (error) => `${error}`
console.log(alpha(error));
})
//#################################################]
const promise1 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("Promise 1 resolved");
}, 1000);
});
const promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("Promise 2 resolved");
}, 500);
});
const promise3 = new Promise((resolve, reject) => {
setTimeout(() => {
reject("Promise 3 rejected");
}, 1500);
});
Promise.race([promise1, promise2, promise3])
.then((result) => {
console.log("First promise to settle:", result);
})
.catch((error) => {
console.log("First promise to reject:", error);
});