Skip to content

Instantly share code, notes, and snippets.

@abirAbuAsim
Created June 13, 2019 04:01
Show Gist options
  • Select an option

  • Save abirAbuAsim/43851888ca61b031ded313cf8c89c526 to your computer and use it in GitHub Desktop.

Select an option

Save abirAbuAsim/43851888ca61b031ded313cf8c89c526 to your computer and use it in GitHub Desktop.

Revisions

  1. abirAbuAsim created this gist Jun 13, 2019.
    9 changes: 9 additions & 0 deletions jsVarExampleUsingForLoop.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    function simpleForLoopToShowVarBehavior() {
    for(var i = 0; i < 10; i++) {
    console.log(i); // You may think that i is scoped only inside this for loop
    }

    console.log(i); // Voila, for some magical reason you see '10' as output of this line
    // which means Javascript Var is not the variable declaration that you dreamt of
    // The i variable gets the value '10' from the last iteration of the for loop
    }