Skip to content

Commit e7efb42

Browse files
author
vitpavlenko
committed
replace let with const
1 parent 1883c8a commit e7efb42

File tree

10 files changed

+21
-21
lines changed

10 files changed

+21
-21
lines changed

JavaScript/4-promises.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const promisify = require('./promisify');
66
const readFile = promisify(fs.readFile);
77

88
function readTextFile(filename) {
9-
let promise = readFile(filename).then(data => data.toString());
9+
const promise = readFile(filename).then(data => data.toString());
1010
return promise;
1111
}
1212

JavaScript/5-catch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const promisify = require('./promisify');
66
const readFile = promisify(fs.readFile);
77

88
function readTextFile(filename) {
9-
let promise = readFile(filename).then(data => data.toString());
9+
const promise = readFile(filename).then(data => data.toString());
1010
return promise;
1111
}
1212

JavaScript/6-onReject.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const promisify = require('./promisify');
66
const readFile = promisify(fs.readFile);
77

88
function readTextFile(filename) {
9-
let promise = readFile(filename).then(data => data.toString());
9+
const promise = readFile(filename).then(data => data.toString());
1010
return promise;
1111
}
1212

JavaScript/8-http.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const httpGet = require('./get-json');
44

55
const baseUrl = 'http://localhost:3000/';
66
httpGet(baseUrl).then((api) => {
7-
let promises = [];
8-
for (let resource of api.resources) {
7+
const promises = [];
8+
for (const resource of api.resources) {
99
promises.push(httpGet(baseUrl + resource));
1010
}
1111
Promise.all(promises).then((values) => {

JavaScript/9-http.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ const async = require('./async');
55

66
const baseUrl = 'http://localhost:3000/';
77
async(function* () {
8-
let api = yield httpGet(baseUrl);
9-
for (let resource of api.resources) {
10-
let data = yield httpGet(baseUrl + resource);
8+
const api = yield httpGet(baseUrl);
9+
for (const resource of api.resources) {
10+
const data = yield httpGet(baseUrl + resource);
1111
console.log(data);
1212
}
1313
});

JavaScript/async-await/http-client.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import httpGet from '../get-json';
55
const baseUrl = 'http://localhost:3000/';
66

77
(async () => {
8-
let api = await httpGet(baseUrl);
9-
for (let resource of api.resources) {
10-
let data = await httpGet(baseUrl + resource);
8+
const api = await httpGet(baseUrl);
9+
for (const resource of api.resources) {
10+
const data = await httpGet(baseUrl + resource);
1111
console.log(data);
1212
}
13-
})();
13+
})();

JavaScript/async.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22

33
module.exports = (asyncFn) => {
4-
let generator = asyncFn();
4+
const generator = asyncFn();
55
let result = generator.next();
66

77
return new Promise((resolve, reject) => {
88
step();
99

1010
function step() {
11-
let promise = Promise.resolve(result.value);
11+
const promise = Promise.resolve(result.value);
1212

1313
if (result.done) {
1414
resolve(promise);

JavaScript/get-json.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ const http = require('http');
55
module.exports = (url) => {
66
return new Promise((resolve, reject) => {
77
http.get(url, res => {
8-
let code = res.statusCode;
8+
const code = res.statusCode;
99
if (code !== 200) {
1010
return reject(new Error(`HTTP status code ${code}`));
1111
}
1212

1313
res.on('error', reject);
1414

15-
let chunks = [];
15+
const chunks = [];
1616
res.on('data', chunk => {
1717
chunks.push(chunk);
1818
});
1919

2020
res.on('end', () => {
21-
let json = Buffer.concat(chunks).toString();
21+
const json = Buffer.concat(chunks).toString();
2222
let object = null;
2323

2424
try {

JavaScript/promisify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function promisify(asyncFunction) {
1010
resolve(result);
1111
}
1212
});
13-
asyncFunction.apply(undefined, args);
13+
asyncFunction(...args);
1414
});
1515
};
1616
};

JavaScript/server.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ const routes = {
2727
};
2828

2929
const server = http.createServer((req, res) => {
30-
let parsedUrl = url.parse(req.url);
30+
const parsedUrl = url.parse(req.url);
3131
let path = parsedUrl.pathname;
3232
if (path.endsWith('/') && path.length > 1) {
3333
path = path.slice(0, -1);
3434
}
3535

36-
let handler = routes[path];
36+
const handler = routes[path];
3737
if (!handler) {
3838
res.writeHead(404);
3939
res.end('Not found');
4040
return;
4141
}
4242

4343
handler(req, (result) => {
44-
let json = JSON.stringify(result);
44+
const json = JSON.stringify(result);
4545
res.writeHead(200, { 'Content-Type': 'application/json' });
4646
res.end(json);
4747
});

0 commit comments

Comments
 (0)