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