diff --git a/challenges/02-javascript-algorithms-and-data-structures/es6.json b/challenges/02-javascript-algorithms-and-data-structures/es6.json index f0084c6c1d..2d24982c73 100644 --- a/challenges/02-javascript-algorithms-and-data-structures/es6.json +++ b/challenges/02-javascript-algorithms-and-data-structures/es6.json @@ -25,20 +25,21 @@ }, { "id": "587d7b87367417b2b2512b3f", - "title": "Explore Problems with the var Keyword", + "title": "Explore Differences Between the var and let Keywords", "description": [ "One of the biggest problems with declaring variables with the var keyword is that you can overwrite variable declarations without an error.", "
var camper = 'James';
var camper = 'David';
console.log(camper);
// logs 'David'
", - "In a small application, you might not run into this type of problem, but when your code becomes larger, you might accidently overwrite a variable that you did not intend to overwrite. Because this behaviour does not throw an error, searching and fixing bugs becomes more difficult.", - "Another problem with the var keyword is that it is hoisted to the top of your code when it compiles. This means that you can use a variable before you declare it.", - "
console.log(camper);
var camper = 'David';
// logs undefined
", - "The code runs in the following order:", - "
  1. The variable camper is declared as undefined.
  2. The value of camper is logged.
  3. David is assigned to camper.
", - "This code will run without an error.", - "A new keyword called let was introduced in ES6 to solve the problems with the var keyword. With the let keyword, all the examples we just saw will cause an error to appear. We can no longer overwrite variables or use a variable before we declare it. Some modern browsers require you to add \"use strict\"; to the top of your code before you can use the new features of ES6.", - "Let's try using the let keyword.", + "As you can see in the code above, the camper variable is originally declared as James and then overridden to be David.", + "In a small application, you might not run into this type of problem, but when your code becomes larger, you might accidently overwrite a variable that you did not intend to overwrite.", + "Because this behavior does not throw an error, searching and fixing bugs becomes more difficult.
", + "A new keyword called let was introduced in ES6 to solve this potential issue with the var keyword.", + "If you were to replace var with let in the variable declarations of the code above, the result would be an error.", + "
let camper = 'James';
let camper = 'David'; // throws an error
", + "This error can be seen in the console of your browser.", + "So unlike var, when using let, a variable with the same name can only be declared once.", "
", - "Replace var with let" + "Update the code so it only uses the let keyword.", + "Note
Remember that since let prevents variables from being overridden, you will need to remove one of the declarations entirely." ], "challengeSeed": [ "var catName;",