var vs. let

With var, a variable can be declared twice and the content gets overwritten:

var camper = "James";
var camper = "David";
console.log(camper); // David

After ES6, we can use let to get rid of this behavior. For example, the following code will throw SyntaxError:

let camper = "James";
let camper = "David";

Last updated