Skip to content
Better HN
Top
New
Best
Ask
Show
Jobs
Search
⌘K
Don't get bitten by Javascript variable hoisting in loops | Better HN
Don't get bitten by Javascript variable hoisting in loops
(opens in new tab)
(thecomputersarewinning.com)
4 points
ithayer
13y ago
1 comments
Share
1 comments
default
newest
oldest
Q_the_Novice
13y ago
JavaScript variables are passed by reference, the variable `i` on the statement: `var msg = txt[i];` will always reference the last value after the loop has executed.
j
/
k
navigate · click thread line to collapse