Permalink
Browse files

Change `let` to `const`

  • Loading branch information...
matt-brendzel committed Jul 1, 2016
1 parent 2928752 commit 3f0cee50c9c86b207e1c556eab73b3f3e0a78995
Showing with 4 additions and 4 deletions.
  1. +4 −4 README.md
@@ -52,7 +52,7 @@ does a promise take when it is constructed?
```js ```js
// remember that callback is something you write, in this case to perform some // remember that callback is something you write, in this case to perform some
// processing on parsed JSON // processing on parsed JSON
let readJSON = function (filename, callback){ const readJSON = function (filename, callback){
fs.readFile(filename, 'utf8', function (err, res){ fs.readFile(filename, 'utf8', function (err, res){
if (err) { if (err) {
return callback(err); // what's going on here? return callback(err); // what's going on here?
@@ -65,7 +65,7 @@ let readJSON = function (filename, callback){
What are some weaknesses in this code? And the following? What are some weaknesses in this code? And the following?


```js ```js
let readJSON = function (filename, callback){ // 👀 here const readJSON = function (filename, callback){ // 👀 here
fs.readFile(filename, 'utf8', function (err, res){ fs.readFile(filename, 'utf8', function (err, res){
if (err) { if (err) {
return callback(err); // pass the error from readFile return callback(err); // pass the error from readFile
@@ -83,7 +83,7 @@ let readJSON = function (filename, callback){ // 👀 here
What about this instead? What about this instead?


```js ```js
let readJSON = function (filename) { // <-- look here const readJSON = function (filename) { // <-- look here
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
fs.readFile(filename, { encoding: 'utf8' }, (err, res) => { fs.readFile(filename, { encoding: 'utf8' }, (err, res) => {
if (err) { if (err) {
@@ -109,7 +109,7 @@ readJSON('./example.jsom')
That's too verbose. This is better: That's too verbose. This is better:


```js ```js
let readJSON = function (filename) { const readJSON = function (filename) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
fs.readFile(filename, { encoding: 'utf8' }, (err, res) => { fs.readFile(filename, { encoding: 'utf8' }, (err, res) => {
if (err) { if (err) {

0 comments on commit 3f0cee5

Please sign in to comment.