DEV Community

Discussion on: JavaScript: Execution Context and Lexical Scope

Collapse
 
aleksandar15 profile image
Aleksandar15

Very well, except that I thought you were also gonna touch upon the let (and/or const) keyword for declaring a variable, thats also if we, in a given interview, mentioned it they would think more highly of ourselves that we know the difference. That is let variable won't let you access it before its initialization. Although hoisted, let is not initialized to a default value (of undefined).

As in your example, it would work similarly if we were to declare let perfectMatch; (gets initialized to undefined) and if we define (initialize) it after the function console.log(), it would still be undefined. But, declaring it after its call -> let throws an ReferenceError and that's why let is more helpful in debugging our code.