Module 1: Understanding Block Scope

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

12
app.js
View File

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