From 315696c16349a8112a6b79a8575948f9d4e24db7 Mon Sep 17 00:00:00 2001 From: Mark Crowther Date: Fri, 10 Jul 2020 10:06:05 +0100 Subject: [PATCH 1/2] Varibale scope example for var and let --- variable-scope-by-example/variable-scope-by-example.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 variable-scope-by-example/variable-scope-by-example.js 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 From baa14d1fd63b15f4ac73d213047f1402713085e5 Mon Sep 17 00:00:00 2001 From: Mark Crowther Date: Fri, 10 Jul 2020 10:07:36 +0100 Subject: [PATCH 2/2] Added Varibale scope --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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/)**