var keyword is that you can overwrite variable declarations without an error.
var camper = 'James';As you can see in the code above, the
var camper = 'David';
console.log(camper);
// logs 'David'
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 accidentally 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.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';This error can be seen in the console of your browser. So unlike
let camper = 'David'; // throws an error
var, when using let, a variable with the same name can only be declared once.
Note the "use strict". This enables Strict Mode, which catches common coding mistakes and "unsafe" actions. For instance:
"use strict";
x = 3.14; // throws an error because x is not declared
let keyword.
var does not exist in code.
testString: getUserInput => assert(!getUserInput('index').match(/var/g),'var does not exist in code.');
- text: catName should be Oliver.
testString: assert(catName === "Oliver", 'catName should be Oliver.');
- text: quote should be "Oliver says Meow!"
testString: assert(quote === "Oliver says Meow!", 'quote should be "Oliver says Meow!"');
```