Skip to content

Commit e034bfa

Browse files
committed
Improve examples
1 parent f0b1890 commit e034bfa

File tree

6 files changed

+11
-8
lines changed

6 files changed

+11
-8
lines changed

JavaScript/1-callback.js

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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)