Module 1: Understanding Block Scope

This commit is contained in:
jason.zhu 2021-05-12 11:41:40 +10:00
parent cfc610bf1a
commit c11b998681

10
app.js
View File

@ -1,9 +1,5 @@
function greeting() {
let message = 'Hello'; let message = 'Hello';
let sayHi = function hi() { if (message === 'Hello') {
let message = 'Hi'; var count = 100; // var is within global scope, when it's not within object or function
};
sayHi();
console.log(message); // Hello as 'Hi' is out of scope
} }
greeting(); console.log(count); // No reference error, which is dangerous