Last active
May 14, 2018 07:48
-
-
Save okjodom/50964bf8ff6930a12aa95fb4c5832737 to your computer and use it in GitHub Desktop.
Javascript Loop family
This file contains 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
/* Three for loops in JavaScript */ | |
const pirates = ['Davy Jones', 'Blackbeard', 'Cap`n Barbossa', 'Hook', 'Long Jon Silver', 'Jack Sparrow']; | |
// classical for loop | |
for (let i = 0; i < pirates.length; i++) { | |
console.log(`Yarrr! Ye can call me ${pirates[i]}`); | |
} | |
// for-in loop | |
for (const index in pirates) { | |
console.log(`Yarrr! Ye can call me ${pirate[index]}`); | |
} | |
// for-of loop. Yarrrr!! | |
for (const pirate of pirates) { | |
console.log(`Yarrr! Ye can call me ${pirate}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment