Module 1: Understanding Block Scope
This commit is contained in:
parent
cfc610bf1a
commit
c11b998681
12
app.js
12
app.js
@ -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
|
Loading…
x
Reference in New Issue
Block a user