Created
December 21, 2015 03:17
-
-
Save sivaprabug/d6fd6c0ef4b0e2e15f1d 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>Hiding global Variables with local variables of the same name</title> | |
| </head> | |
| <body> | |
| <script> | |
| var myVar = "Global Variable"; | |
| function printing() { | |
| var myVar; | |
| console.log(myVar); | |
| var myVar = "Local variable inside the function" | |
| console.log(myVar); | |
| // Window object means we can access the global variable inside the function | |
| console.log(window.myVar); | |
| } | |
| printing(); | |
| console.log(myVar); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment