Skip to content

Instantly share code, notes, and snippets.

@abel-masila
Created February 25, 2018 14:57
Show Gist options
  • Save abel-masila/0a71d4f1fa717aa065fa71812dcfae3c to your computer and use it in GitHub Desktop.
Save abel-masila/0a71d4f1fa717aa065fa71812dcfae3c to your computer and use it in GitHub Desktop.
function loop(arr) {
// i IS NOT known here
// j IS NOT known here
for( var i = 0; i < arr.length; i++ ) {
// i IS known here
}
// i IS known here
// j IS NOT known here
for( let j = 0; j < arr.length; j++ ) {
// j IS known here
}
// i IS known here
// j IS NOT known here
}
///Here, we can see that our variable j is only known in the first for loop, but not before and after.
//Yet, our variable i is known in the entire function from the moment it is defined onward.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment