-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum.js
More file actions
46 lines (37 loc) · 836 Bytes
/
Copy pathsum.js
File metadata and controls
46 lines (37 loc) · 836 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
1. // Basic concept jest
function sum(a,b){
return a + b;
}
module.exports = sum;
2. // toThrow()
function myFunction(input){
if(typeof input != 'number'){
throw new Error('Invalid Input')
}
}
module.exports = myFunction;
3. // Asynchronus Code
function fetchData(callback){
setTimeout(()=>{
callback("Peanut butter")
},1000)
}
module.exports = fetchData
4. // Promise Asynchronous Code
function fetchPromise(){
return new Promise((resolve,reject)=>
setTimeout(()=>{
resolve("peanut butter")
},1000)
)
}
module.exports = fetchPromise
5.// Async Await Asynchronous code
function fetchAsync() {
return new Promise((resolve, reject) =>
setTimeout(() => {
resolve("peanut Jam");
}, 1000)
);
}
module.exports = fetchAsync;