-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconst_let.js
49 lines (39 loc) · 1.12 KB
/
const_let.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*jshint esversion: 6 */
(function () {
'use strict';
// Const
// Use const to decalre variables that
// won't change.
const name = "Albää";
const title = "Engineer";
const wage = 10000;
// Variables delcared with var can be re-declared
// and they attach to the global window object.
var question = "Hello?";
//var question = "What?";
console.log(question);
// Variables delcared with let can't be re-declared
// and they do NOT attach to the global window object.
let answer = "Yes?";
//let answer = "No.";
console.log(answer);
// Variables declared with let do not get hoisted
// to the top of the function scope.
function foo(bar) {
if (bar) {
console.log(baz); // ReferenceError: baz is not defined
let baz = 'Bar is truthy!';
}
}
function count() {
for (let i = 0; i < 10; i++) {
console.log("LET:" + i);
}
// Our let variable i is unedfiend in this scope
for (var j = 0; j < 10; j++) {
console.log("VAR:" +j);
}
// Our var variable j is NOT unedfiend in this scope
}
count();
}());