-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yoko Oh Noes confused about hoisting and loops #733
Comments
Huh. Thanks for the report, Bob! |
This is actually one of the really catchy things about JS, it can be pretty confusing. If |
In Ono-chan's defense, it's usually not considered good practice to initialize a variable multiple times in the same scope; I think the more commonplace approach would be something like: var t;
for (var i = 0; i < 10; i++) {
t = undefined;
if (random() < 0.2) {
t = 1;
}
if (t) {
println(i + ". bingo");
}
} edit: that being said, i still think this should be considered a bug and not a feature |
it's usually not considered good practice to initialize a variable multiple times in the same scope. doit(); |
See the demo program at https://www.khanacademy.org/computer-programming/confused/5208304615768064 . It attempts to initialize a variable declared inside the body of a loop to undefined causing the complaint "It's not necessary to initialize 't' to 'undefined'." which is certainly not the case.
The text was updated successfully, but these errors were encountered: