Skip to content

Commit 3243eff

Browse files
committed
EcmaScript 6 const and let examples
1 parent a7285d9 commit 3243eff

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

chapter01/02-Variables.js

+48
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ console.log("price: "+ price);
1414
console.log("nullVar: "+ nullVar);
1515
console.log("und: "+ und);
1616

17+
//******* EcmaScript 6: let and const keywords
18+
// EcmaScript 6 Constants
19+
const PI = 3.141593;
20+
//PI = 3.0; //throws error
21+
console.log(PI);
22+
23+
// EcmaScript 6: let is the new var
24+
var framework = 'Angular';
25+
var framework = 'React';
26+
console.log(framework);
27+
28+
let language = 'JavaScript!';
29+
//let language = 'Ruby!'; //throws error
30+
console.log(language);
31+
1732
//******* Variable Scope
1833

1934
var myVariable = 'global';
@@ -35,3 +50,36 @@ console.log(myFunction()); //{2}
3550
console.log(myOtherVariable); //{3}
3651
console.log(myOtherFunction()); //{4}
3752
console.log(myOtherVariable); //{5}
53+
54+
//******* EcmaScript 6: variables scope
55+
let movie = 'Lord of the Rings';
56+
//var movie = 'Batman v Superman'; //throws error, variable movie already declared
57+
58+
function starWarsFan(){
59+
let movie = 'Star Wars';
60+
return movie;
61+
}
62+
63+
function marvelFan(){
64+
movie = 'The Avengers';
65+
return movie;
66+
}
67+
68+
function blizzardFan(){
69+
let isFan = true;
70+
let phrase = 'Warcraft';
71+
console.log('Before if: ' + phrase);
72+
if (isFan){
73+
let phrase = 'initial text';
74+
phrase = 'For the Horde!';
75+
console.log('Inside if: ' + phrase);
76+
}
77+
phrase = 'For the Alliance!';
78+
console.log('After if: ' + phrase);
79+
}
80+
81+
console.log(movie);
82+
console.log(starWarsFan());
83+
console.log(marvelFan());
84+
console.log(movie);
85+
blizzardFan();

0 commit comments

Comments
 (0)