-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path6-async-await.js
More file actions
41 lines (33 loc) · 854 Bytes
/
6-async-await.js
File metadata and controls
41 lines (33 loc) · 854 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
'use strict';
const sum = async (a, b) => {
if (typeof a === 'number' && typeof b === 'number') {
return a + b;
}
throw new Error('a and b should be numbers');
};
(async () => {
const x = 2;
const y = 3;
try {
const total = await sum(x, y);
console.log({ x, y, total });
} catch (err) {
console.error({ x, y, err });
}
const z = 7;
const c = 'A';
try {
const res = await sum(z, c);
console.log({ z, c, res });
} catch (err) {
console.error({ z, c, err });
}
/*
const res = await sum(z, c);
console.log({ z, c, res });
UnhandledPromiseRejectionWarning: Error: a and b should be numbers
DeprecationWarning: Unhandled promise rejections are deprecated.
In the future, promise rejections that are not handled will terminate
the Node.js process with a non-zero exit code.
*/
})();