Created
August 7, 2013 21:08
-
-
Save turtlemonvh/6178700 to your computer and use it in GitHub Desktop.
For loop scope test in javascript
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
for(var i=1; i<10; i++){var x = 3;}; | |
x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, javascript doesn't have block scope.
If you're iterating with
.Each
, you can get function scope. For example:var a = [1,2,3,4,5]; a.forEach(function(v){ console.log(v); }); try{v}catch(e){console.log('v is not defined anymore')}