javascript-tutorial / javascript-tutorial/en.javascript.info

closures - uninitialized vs undefined

Open
#3,895 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
HTML
Stars
25.5k
Forks
4k
PR merge metrics
No merged PRs in 30d

Description

in [this article](https://javascript.info/closure), we are discussing lexical environments, and the scope of variables.
upon initialization, variables are defined as `` because "[the engine knows about the variable, but it cannot be referenced until it has been declared with `let`](https://javascript.info/closure#step-1-variables)"

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the closure article's lexical-environment and nested-function sections, then compare the labels in lexenv-nested-makecounter-2.svg and lexenv-nested-makecounter-3.svg. Verify whether the diagrams should distinguish from undefined, and update those SVGs only if the JavaScript behavior supports the proposed correction.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.