@@ -14,6 +14,21 @@ console.log("price: "+ price);
14
14
console . log ( "nullVar: " + nullVar ) ;
15
15
console . log ( "und: " + und ) ;
16
16
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
+
17
32
//******* Variable Scope
18
33
19
34
var myVariable = 'global' ;
@@ -35,3 +50,36 @@ console.log(myFunction()); //{2}
35
50
console . log ( myOtherVariable ) ; //{3}
36
51
console . log ( myOtherFunction ( ) ) ; //{4}
37
52
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