Last active
December 25, 2015 03:29
-
-
Save rishabg/6909732 to your computer and use it in GitHub Desktop.
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
| // 1. Can you predict what will be 'hollered'. | |
| // 2. Walk through the execution as you think out loud. | |
| function holler(val, name, scope){ | |
| console.log("[ "+ scope +" ] variable '" + name + "' has value: " + val) | |
| } | |
| var a = '2'; | |
| var c = 'c'; | |
| function foo() { | |
| a = '3'; | |
| var c = 'd'; | |
| holler(a, 'a', 'In foo'); | |
| holler(c, 'c', 'In foo'); | |
| var x = 1; | |
| if (x) { | |
| (function () { | |
| var x = 2; | |
| holler(c,'c', 'In anon function'); | |
| }()); | |
| holler(x,'x','In if block'); | |
| } | |
| holler(x,'x', 'In foo after if block'); | |
| function bar() { | |
| var x = 3; | |
| a = '4'; | |
| } | |
| holler(x,'x', 'In foo after bar'); | |
| holler(a,'a', 'In foo after bar'); | |
| bar(); | |
| holler(x,'x', 'In foo after bar() invocation'); | |
| holler(a,'a', 'In foo after bar() invocation'); | |
| } | |
| holler(a, 'a', 'after foo'); | |
| holler(c, 'c', 'after foo'); | |
| foo(); | |
| holler(a, 'a', 'after foo() invocation'); | |
| holler(c, 'c', 'after foo() invocation'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment