From c11b998681b6fdc7e809b323d4f48072bc8dfbf7 Mon Sep 17 00:00:00 2001 From: "jason.zhu" Date: Wed, 12 May 2021 11:41:40 +1000 Subject: [PATCH] Module 1: Understanding Block Scope --- app.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app.js b/app.js index c1c82aa..12e7f3d 100644 --- a/app.js +++ b/app.js @@ -1,9 +1,5 @@ -function greeting() { - let message = 'Hello'; - let sayHi = function hi() { - let message = 'Hi'; - }; - sayHi(); - console.log(message); // Hello as 'Hi' is out of scope +let message = 'Hello'; +if (message === 'Hello') { + var count = 100; // var is within global scope, when it's not within object or function } -greeting(); \ No newline at end of file +console.log(count); // No reference error, which is dangerous \ No newline at end of file