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
}
var a = 0;
var b = 0;
if (a === 0) {
let a = 1; // The scope is inside the if-block
var b = 1; // The scope is inside the function
console.log(a); // 1
console.log(b); // 1
}
console.log(a); // 0
console.log(b); // 1