GeezerVison is showing github.com — Use typeof without round brackets · HowProgrammingWorks/Errors@c768877
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 |
| 3 | 3 | const sum = (a, b) => { | 4 | | - if (typeof(a) === 'number' && typeof(b) === 'number') { | | 4 | + if (typeof a === 'number' && typeof b === 'number') { | 5 | 5 | return a + b; | 6 | 6 | } else { | 7 | 7 | throw new Error('a and b should be numbers'); | @@ -10,12 +10,12 @@ const sum = (a, b) => { | 10 | 10 |
| 11 | 11 | try { | 12 | 12 | console.log(sum(2, 3)); | 13 | | -} catch (e) { | 14 | | - console.log(e.message); | | 13 | +} catch (err) { | | 14 | + console.log(err.message); | 15 | 15 | } | 16 | 16 |
| 17 | 17 | try { | 18 | 18 | console.log(sum(7, 'A')); | 19 | | -} catch (e) { | 20 | | - console.log(e.message); | | 19 | +} catch (err) { | | 20 | + console.log(err.message); | 21 | 21 | } |
Collapse file Copy file name to clipboardExpand all lines: JavaScript/2-sync-tuple.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 |
| 3 | 3 | const sum = (a, b) => { | 4 | | - if (typeof(a) === 'number' && typeof(b) === 'number') { | | 4 | + if (typeof a === 'number' && typeof b === 'number') { | 5 | 5 | return [null, a + b]; | 6 | 6 | } else { | 7 | 7 | return [new Error('a and b should be numbers')]; | |
Collapse file Copy file name to clipboardExpand all lines: JavaScript/3-async.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 |
| 3 | 3 | const sum = (a, b, callback) => { | 4 | | - if (typeof(a) === 'number' && typeof(b) === 'number') { | | 4 | + if (typeof a === 'number' && typeof b === 'number') { | 5 | 5 | callback(null, a + b); | 6 | 6 | } else { | 7 | 7 | callback(new Error('a and b should be numbers')); | |
Collapse file Copy file name to clipboardExpand all lines: JavaScript/4-uncaught.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,7 +5,7 @@ process.on('uncaughtException', err => { | 5 | 5 | }); | 6 | 6 |
| 7 | 7 | const sum = (a, b) => { | 8 | | - if (typeof(a) === 'number' && typeof(b) === 'number') { | | 8 | + if (typeof a === 'number' && typeof b === 'number') { | 9 | 9 | return a + b; | 10 | 10 | } else { | 11 | 11 | throw new Error('a and b should be numbers'); | |
Collapse file Copy file name to clipboardExpand all lines: JavaScript/5-promise.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 |
| 3 | 3 | const sum = (a, b) => new Promise((resolve, reject) => { | 4 | | - if (typeof(a) === 'number' && typeof(b) === 'number') { | | 4 | + if (typeof a === 'number' && typeof b === 'number') { | 5 | 5 | resolve(a + b); | 6 | 6 | } else { | 7 | 7 | reject(new Error('a and b should be numbers')); | |
Collapse file Copy file name to clipboardExpand all lines: JavaScript/6-async-await.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 |
| 3 | 3 | const sum = async (a, b) => { | 4 | | - if (typeof(a) === 'number' && typeof(b) === 'number') { | | 4 | + if (typeof a === 'number' && typeof b === 'number') { | 5 | 5 | return a + b; | 6 | 6 | } else { | 7 | 7 | throw new Error('a and b should be numbers'); | @@ -18,8 +18,8 @@ const sum = async (a, b) => { | 18 | 18 |
| 19 | 19 | try { | 20 | 20 | console.log(await sum(7, 'A')); | 21 | | - } catch (e) { | 22 | | - console.log(e.message); | | 21 | + } catch (err) { | | 22 | + console.log(err.message); | 23 | 23 | } | 24 | 24 |
| 25 | 25 | })(); |
|