diff --git a/README.md b/README.md index 14a432d..ce8d73b 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ If there's anything that you think could be improved due to misunderstanding, th # The 1000 Things Structure of the repo Things are as *folder > main js file*, along with the supporting HTML and CSS files. +(9) Scope example > variable-scope-by-example.js
(8) Maths Hero > updated-maths-engine.js
(7) Game Sounds > soundPlayer.js
(6) Name Changer > namechange.js
@@ -25,7 +26,7 @@ Structure of the repo Things are as *folder > main js file*, along with the supp (2) Date and Time > myYearAndDate.js
(1) Date and Time > myDayFunction.js -**Only 992 to go... o_O** +**Only 991 to go... o_O** # Courses and Sources **[https://www.sololearn.com/Course/JavaScript/](https://www.sololearn.com/Course/JavaScript/)** diff --git a/variable-scope-by-example/variable-scope-by-example.js b/variable-scope-by-example/variable-scope-by-example.js new file mode 100644 index 0000000..ce79eab --- /dev/null +++ b/variable-scope-by-example/variable-scope-by-example.js @@ -0,0 +1,10 @@ +var aVariableOutsideACodeBlock = 10; + +if (aVariableOutsideACodeBlock == 10) { + var aVariableINSIDE = 20; + console.log("(aVariableOutsideACodeBlock) equals " + aVariableOutsideACodeBlock); + console.log("(aVariableINSIDE) equals " + aVariableINSIDE); +} +// The below works if we use var, change the var keywords to let and it will fail +// This demonstrates the better scope control of let +console.log("(aVariableINSIDE) called from outside equals " + aVariableINSIDE); \ No newline at end of file