Q2: improve explanation for question 2 (var vs let hoisting)#845
Open
aalex198 wants to merge 1 commit into
Open
Q2: improve explanation for question 2 (var vs let hoisting)#845aalex198 wants to merge 1 commit into
aalex198 wants to merge 1 commit into
Conversation
… all 22 translations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi Lydia! 👋
First of all, thank you so much for this amazing repository! I really appreciate the effort you've put into maintaining it and all the translations. ❤️
Summary
This PR improves the technical explanation for Question 2 (var vs let in a
forloop withsetTimeout) across all 22 language versions of the README.Problem
The current explanation states that
varmakes the variable global andletis block-scoped, but it doesn't explain whyvarshares a single value across all iterations whileletcreates a new value per iteration. Understanding the memory allocation difference is key to grasping this classic JavaScript interview question.Changes
Added one sentence to each paragraph of the answer (existing text was preserved):
varallocates a single memory slot for the variable, so each iteration overwrites the same variable rather than creating a new one.letcreates a new binding (a new memory slot) for each iteration, which is why eachsetTimeoutcallback captures a different value.Why This Matters
The
varvsletbehavior in loops is one of the most common JavaScript interview questions. The previous explanation correctly described the outcome but didn't explain the underlying mechanism (memory allocation during hoisting). This change makes the explanation more complete and technically accurate for learners.