en.javascript.info icon indicating copy to clipboard operation
en.javascript.info copied to clipboard

closures - uninitialized vs undefined

Open aredmondd opened this issue 3 months ago • 1 comments

in this article, we are discussing lexical environments, and the scope of variables. upon initialization, variables are defined as <unitialized> because "the engine knows about the variable, but it cannot be referenced until it has been declared with let"

Image Image

later in the article, when referencing nested lexical environments in functions, a variable is initialized as undefined. from my understanding, this is incorrect, as the engine knows about the variable, but is not referenced yet since it hasn't been declared.

Image Image

i believe that we need to change the following SVG's to reflect this change: https://github.com/javascript-tutorial/en.javascript.info/blob/master/1-js/06-advanced-functions/03-closure/lexenv-nested-makecounter-2.svg https://github.com/javascript-tutorial/en.javascript.info/blob/master/1-js/06-advanced-functions/03-closure/lexenv-nested-makecounter-3.svg

if this is an incorrect assumption, please help me understand why it's undefined instead of uninitialized! i'd love to learn more about how this all works.

aredmondd avatar Oct 17 '25 12:10 aredmondd

I think at that point the execution already passed the let declaration, so it's not "uninitialized".

note: chatgpt "partialy" agrees wirh a long explanation i didnt read. then concludes the issue is wrong. And offered a step by step correlation code-svg i didnt read either. Sorry my lazyness.

joaquinelio avatar Oct 19 '25 15:10 joaquinelio