Last active
August 29, 2015 14:07
-
-
Save ecasilla/17946f3a07bc99085af4 to your computer and use it in GitHub Desktop.
Using this as a way to show students about closures and scope
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 <=5; i++){ | |
| setTimeout(function(){ | |
| console.log("vaule of i is: " + i); | |
| },i*1000); | |
| } | |
| for (var i = 1; i <=5; i++){ | |
| (function(i){ | |
| setTimeout(function(){ | |
| console.log("vaule of i is: " + i); | |
| },i*1000); | |
| })(i) | |
| } | |
| ++++++++++++++++++++++++++++++++++++++ | |
| ES6 Way | |
| for (let i = 1; i <=5; i++){ | |
| setTimeout(function(){ | |
| console.log("vaule of i is: " + i); | |
| },i*1000); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment