Last active
August 29, 2015 13:59
-
-
Save davidchase/10669005 to your computer and use it in GitHub Desktop.
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
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