Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Don't get bitten by Javascript variable hoisting in loops | Better HN
Don't get bitten by Javascript variable hoisting in loops
(thecomputersarewinning.com)
4 points · by
ithayer
· 14y ago · 1 comment
Comments
[–]
Q_the_Novice
14y 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.