Created
November 11, 2010 08:15
-
-
Save torgeir/672189 to your computer and use it in GitHub Desktop.
JavaScript owns your scope
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
var a = 1; | |
b = 3; | |
var s = 1; | |
(function () { | |
a = 2; | |
b = 4; | |
var c = 3; | |
d = 1; | |
s = 2; | |
if (false) { | |
var s; | |
function f () { | |
var s = 7; | |
return s; | |
} | |
} | |
assert( .. === 2); | |
// assert( .. === 4); | |
// assert( .. === 3); | |
// assert( .. === 1); | |
// assert( .. === 2); | |
// assert( .. === 7); | |
})(); | |
// assert( .. === 2); | |
// assert( .. === 4); | |
// assert( .. === 'undefined'); | |
// assert( .. === 1); | |
// assert( .. === 1); | |
// assert( .. === 'undefined'); | |
function assert (what) { | |
if (what !== true) { | |
throw 'assertion failed'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment