I am trying to understand both let and var keywords. It is not clear for me why do I get 'undefined' when I use let keyword?
let currentScope = 'global';
function print() {
let currentScope = 'local';
console.log(this.currentScope); //undefined
console.log(currentScope); //local
}
print();
console.log(currentScope); //global
and here I use var
var currentScope = 'global';
function print() {
var currentScope = 'local';
console.log(this.currentScope); //global
console.log(currentScope); //local
}
print();
console.log(currentScope); //global