18. function varTest() {
var x = 31;
if (true) {
var x = 71; // same variable!
console.log(x); // 71
}
console.log(x); // 71
}
function letTest() {
let x = 31;
if (true) {
let x = 71; // different variable
console.log(x); // 71
}
console.log(x); // 31
}
19. const MY_FAV = 7;
// this will fail silently in Firefox and
Chrome (but does not fail in Safari)
MY_FAV = 20;
// will print 7
console.log("my favorite number is: " +
MY_FAV);
// trying to redeclare a constant throws an
error
const MY_FAV = 20;
// the name MY_FAV is reserved for constant
above, so this will also fail
var MY_FAV = 20;