-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path3-async.js
More file actions
29 lines (26 loc) · 510 Bytes
/
Copy path3-async.js
File metadata and controls
29 lines (26 loc) · 510 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
'use strict';
const sum = (a, b, callback) => {
if (typeof a === 'number' && typeof b === 'number') {
callback(null, a + b);
} else {
callback(new Error('a and b should be numbers'));
}
};
const x = 2;
const y = 3;
sum(x, y, (err, total) => {
if (err) {
console.error({ x, y, err });
return;
}
console.log({ x, y, total });
});
const z = 7;
const c = 'A';
sum(z, c, (err, res) => {
if (err) {
console.error({ z, c, err });
return;
}
console.log({ z, c, res });
});