forked from liammclennan/JavaScript-Koans
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabout_scope.js
More file actions
28 lines (22 loc) · 907 Bytes
/
about_scope.js
File metadata and controls
28 lines (22 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module("About Scope (topics/about_scope.js)");
thisIsAGlobalVariable = 77;
test("global variables", function() {
equals(thisIsAGlobalVariable, __, 'is thisIsAGlobalVariable defined in this scope?');
});
test("variables declared inside of a function", function() {
var outerVariable = "outer";
// this is a self-invoking function. Notice that it calls itself at the end ().
(function() {
var innerVariable = "inner";
equals(outerVariable, __, 'is outerVariable defined in this scope?');
equals(innerVariable, __, 'is innerVariable defined in this scope?');
})();
equals(outerVariable, __, 'is outerVariable defined in this scope?');
var isInnerVariableDefined = true;
try {
innerVariable
} catch(e) {
isInnerVariableDefined = false;
}
equals(isInnerVariableDefined, __, 'is innerVariable defined in this scope?');
});