Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e034bfa

Browse filesBrowse files
committed
Improve examples
1 parent f0b1890 commit e034bfa
Copy full SHA for e034bfa

File tree

Expand file treeCollapse file tree

6 files changed

+11
-8
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+11
-8
lines changed

‎JavaScript/1-callback.js

Copy file name to clipboard
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
'use strict';
22

33
const add = (a, b) => a + b;
4-
const sum = (a, b, callback) => callback(a + b);
4+
const res = add(2, 3);
5+
console.log(`add(2, 3) = ${res}`);
56

6-
console.log('add(5, 2) =', add(5, 2));
7-
sum(5, 2, console.log.bind(null, 'sum(5, 2) ='));
7+
const sum = (a, b, callback) => callback(a + b);
8+
sum(2, 3, (res) => {
9+
console.log(`sum(2, 3) = ${res}`);
10+
});

‎JavaScript/6-listener.js

Copy file name to clipboardExpand all lines: JavaScript/6-listener.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const iterate = (array, listener) => {
99
const cities = ['Kiev', 'London', 'Beijing'];
1010

1111
const print = (city) => {
12-
console.log('City:', city);
12+
console.log({ city });
1313
};
1414

1515
iterate(cities, print);

‎JavaScript/7-listener-timer.js

Copy file name to clipboardExpand all lines: JavaScript/7-listener-timer.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ const iterate = (array, listener) => {
1111

1212
const cities = ['Kiev', 'London', 'Beijing'];
1313

14-
const print = (city) => console.log('Next city:', city);
14+
const print = (city) => console.log(`Next city: ${city}`);
1515

1616
iterate(cities, print);

‎JavaScript/8-event.js

Copy file name to clipboardExpand all lines: JavaScript/8-event.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const adder = (initial) => {
1818
// Usage
1919

2020
const maxReached = (value) => {
21-
console.log('max value reached, value: ' + value);
21+
console.log(`Max value reached, value: ${value}`);
2222
};
2323

2424
const a1 = adder(10).max(100, maxReached)(-12);

‎JavaScript/9-event-emitter.js

Copy file name to clipboardExpand all lines: JavaScript/9-event-emitter.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { EventEmitter } = require('node:events');
55
const emitter = new EventEmitter();
66

77
emitter.on('new city', (city) => {
8-
console.log('Emitted city:', city);
8+
console.log(`Emitted city: ${city}`);
99
});
1010

1111
emitter.on('data', (array) => {

‎JavaScript/b-errors.js

Copy file name to clipboardExpand all lines: JavaScript/b-errors.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const adder = (value) => {
2727
// error-first
2828
const maxReached = (err, value) => {
2929
if (err) throw err;
30-
console.log('value:', value);
30+
console.log({ value });
3131
};
3232

3333
try {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.