Created
December 21, 2015 03:18
-
-
Save sivaprabug/a0b2a0449e14af10a23e 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()"; | |
| var grandParentVariable = "grandParent() Variable" | |
| console.log(grandParentVariable); | |
| function parent() { | |
| var myVar = "A Variable local to parent()"; | |
| var parentVariable = "parent() Variable" | |
| console.log(parentVariable); | |
| function child() { | |
| var myVar = "A Variable local to child()"; | |
| console.log(myVar); | |
| var childVariable = "Child() Variable" | |
| console.log(childVariable); | |
| } | |
| child(); | |
| } | |
| parent(); | |
| } | |
| grandParent(); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment