let declaration shows "undefined" when invoked with "this" in global scope

44 views Asked by At

the question is best explained with code:

let c = 1;
let d = 2;
function show() {
console.log(this.c, this.d);
}
// show() returns "undefined undefined"

var a = 1;
var b = 2;
function display() {
console.log(this.a, this.b);
}
// display() returns "1 2"

why is this?

0

There are 0 answers