Skip to content

Instantly share code, notes, and snippets.

@davidchase
Last active August 29, 2015 13:59
Show Gist options
  • Save davidchase/10669005 to your computer and use it in GitHub Desktop.
Save davidchase/10669005 to your computer and use it in GitHub Desktop.
for (var i = 1; i <= 100; i++) {
var str = '';
if (i % 3 === 0) str += 'Fizz';
if (i % 5 === 0) str += 'Buzz';
console.log(str || i);
}
// More correct way define str outside of loop
// either way gets hoisted to top of scope in this case
// global environment, in browser the window object
var str;
for (var i = 1; i <= 100; i++) {
str = '';
if (i % 3 === 0) str += 'Fizz';
if (i % 5 === 0) str += 'Buzz';
console.log(str || i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment