Created
December 21, 2015 03:18
-
-
Save sivaprabug/c3cc794086c31c7a8067 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Scope Chain</title> | |
| </head> | |
| <p> | |
| <ul> | |
| <li>When you have nested functions you can create a scope 'Chain'</li> | |
| <li>The browser travels up this chain when looking for a variables value</li> | |
| </ul> | |
| </p> | |
| <body> | |
| <script> | |
| var myVar = "A global Variable"; | |
| function grandParent() { | |
| var myVar = "A Variable local to grandParent()"; | |
| console.log(myVar); | |
| function parent() { | |
| var myVar = "A Variable local to parent()"; | |
| console.log(myVar); | |
| function child() { | |
| var myVar = "A Variable local to child()"; | |
| console.log(myVar); | |
| } | |
| child(); | |
| window.child = child; | |
| } | |
| parent(); | |
| window.parent = parent; | |
| } | |
| grandParent(); | |
| window.grandParent = grandParent; | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment