Skip to content

Commit 1d236fd

Browse files
committed
var -> et
1 parent 6a9f66e commit 1d236fd

File tree

45 files changed

+304
-294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+304
-294
lines changed

1-js/1-getting-started/2-es-modern-now/article.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ The [latest standard](http://www.ecma-international.org/publications/standards/E
55

66
As it includes a lot of new features, most browsers implement them partially. You can find the current state of the support at [](https://kangax.github.io/compat-table/es6/).
77

8+
## Single-engine app
9+
810
If a project is developed for a single JavaScript engine, like V8 (Node.JS, Chrome), then we can use V8-supported features. That's a lot.
911

12+
Most notably, V8 supports many of the new features only if the code is running in the "strict mode" (modern mode), which should be enabled explicitly using a directive `'use strict';` at the start.
13+
14+
You will find most code in this tutorial using this directive and, because of that, runnable in Chrome.
15+
1016
But what if we're writing a cross-browser application? Different browsers support different subsets of ES-2015.
1117

1218
Here comes Babel.JS.
@@ -68,13 +74,13 @@ That doesn't mean that the example is wrong! It's just the browser lacking the s
6874

6975
[Chrome Canary](https://www.google.com/chrome/browser/canary.html) is recommended, most examples work in it.
7076

71-
[Firefox Developer Edition](https://www.mozilla.org/en-US/firefox/channel/#developer) is fine too, but it has certain glitches. Like: [let](/let-const) variables working only with when the script type contains `version=1.7` or `1.8`: `<script type="application/javascript;version=1.7">`. Most other browsers do not understand such script type. This site uses a special trick to workaround.
77+
[Firefox Developer Edition](https://www.mozilla.org/en-US/firefox/channel/#developer) is fine too, but it has certain glitches. Like: [let](/let-const) variables working only with when the script type contains `version=1.7` or `1.8`: `<script type="application/javascript;version=1.7">`. Most other browsers do not understand such script type. This site uses a special trick to workaround that, so that the scripts work in both Firefox and other browsers.
7278

73-
And in any case you can go [Babel: try it out](https://babeljs.io/repl/) page and run the example there!
79+
And even if your browser does not support some code, you can run it through Babel.JS, on the page [Babel: try it out](https://babeljs.io/repl/)!
7480

75-
On production everyone's using Babel anyway.
81+
That would be fine, because on production everyone's using Babel anyway.
7682

7783
Once again, let's note that the most up-to-date situation with support is reflected on [](https://kangax.github.io/compat-table/es6/).
7884

79-
Now we can go coding, but we need a good code editor for that, right? That is discussed in the next session.
85+
Now we can go coding, but we need a good code editor for that. That is discussed in the next session.
8086

1-js/2-first-steps/11-uibasic/1-simple-page/solution.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ JavaScript-code:
22

33
```js
44
//+ demo run
5-
var name = prompt("What is your name?", "");
5+
let name = prompt("What is your name?", "");
66
alert( name );
77
```
88

@@ -15,7 +15,9 @@ The full page:
1515
<body>
1616

1717
<script>
18-
var name = prompt("What is your name?", "");
18+
'use strict';
19+
20+
let name = prompt("What is your name?", "");
1921
alert( name );
2022
</script>
2123

1-js/2-first-steps/11-uibasic/article.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ As with `alert`, the `prompt` window is modal.
4545

4646
```js
4747
//+ run
48-
var age = prompt('How old are you?', 100);
48+
let age = prompt('How old are you?', 100);
4949

5050
alert(`You are ${age} years old!`)
5151
```
@@ -57,14 +57,14 @@ Run this code in Internet Explorer to see that:
5757

5858
```js
5959
//+ run
60-
var test = prompt("Test");
60+
let test = prompt("Test");
6161
```
6262

6363
So, to look good in IE, it's recommended to always provide the second argument:
6464

6565
```js
6666
//+ run
67-
var test = prompt("Test", ''); // <-- for IE
67+
let test = prompt("Test", ''); // <-- for IE
6868
```
6969
[/warn]
7070

@@ -85,7 +85,7 @@ For example:
8585

8686
```js
8787
//+ run
88-
var isBoss = confirm("Are you the boss?");
88+
let isBoss = confirm("Are you the boss?");
8989

9090
alert( isBoss ); // true is OK is pressed
9191
```

1-js/2-first-steps/12-ifelse/2-check-standard/ifelse_task2/index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
<body>
55
<script>
6-
var value = prompt('What is the "official" name of JavaScript?', '');
6+
'use strict';
7+
8+
let value = prompt('What is the "official" name of JavaScript?', '');
79

810
if (value == 'EcmaScript') {
911
alert('Right!');
@@ -15,4 +17,4 @@
1517

1618
</body>
1719

18-
</html>
20+
</html>

1-js/2-first-steps/12-ifelse/3-sign/if_sign/index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<body>
55

66
<script>
7-
var value = prompt('Type a number', 0);
7+
'use strict';
8+
9+
let value = prompt('Type a number', 0);
810

911
if (value > 0) {
1012
alert(1);
@@ -17,4 +19,4 @@
1719

1820
</body>
1921

20-
</html>
22+
</html>

1-js/2-first-steps/12-ifelse/3-sign/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
```js
44
//+ run
5-
var value = prompt('Type a number', 0);
5+
let value = prompt('Type a number', 0);
66

77
if (value > 0) {
88
alert( 1 );

1-js/2-first-steps/12-ifelse/4-check-login/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
```js
44
//+ run demo
5-
var userName = prompt('Who's there?', '');
5+
let userName = prompt('Who's there?', '');
66
77
if (userName == 'Admin') {
88
9-
var pass = prompt('Password?', '');
9+
let pass = prompt('Password?', '');
1010
1111
if (pass == 'TheMaster') {
1212
alert( 'Welcome!' );

1-js/2-first-steps/12-ifelse/6-rewrite-if-else-question/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22

33
```js
4-
var message = (login == 'Employee') ? 'Hello' :
4+
let message = (login == 'Employee') ? 'Hello' :
55
(login == 'Director') ? 'Greetings' :
66
(login == '') ? 'No login' :
77
'';

1-js/2-first-steps/12-ifelse/6-rewrite-if-else-question/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Rewrite `if..else` using multiple ternary operators `'?'`.
77
For readability, please let the code span several lines.
88

99
```js
10-
var message;
10+
let message;
1111

1212
if (login == 'Employee') {
1313
message = 'Hello';

1-js/2-first-steps/12-ifelse/article.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ For example:
1212

1313
```js
1414
//+ run
15-
var year = prompt('In which year was ECMAScript-2015 specification published?', '');
15+
let year = prompt('In which year was ECMAScript-2015 specification published?', '');
1616

1717
*!*
1818
if (year == 2015) alert( 'You are right!' );
@@ -63,7 +63,7 @@ if (1) { // 1 is truthy
6363
We can also pass a pre-evaluated logical value to `if`. For example, in a variable like here:
6464
6565
```js
66-
var cond = (year == 2015); // equality evaluates to true or false
66+
let cond = (year == 2015); // equality evaluates to true or false
6767
6868
if (cond) {
6969
...
@@ -77,7 +77,7 @@ The `if` operator may contain an optional "else" block. It executes when the con
7777
For example:
7878
```js
7979
//+ run
80-
var year = prompt('In which year was ECMAScript-2015 specification published?', '');
80+
let year = prompt('In which year was ECMAScript-2015 specification published?', '');
8181
8282
if (year == 2015) {
8383
alert( 'You guessed it right!' );
@@ -94,7 +94,7 @@ For example:
9494
9595
```js
9696
//+ run
97-
var year = prompt('In which year was ECMAScript-2015 specification published?', '');
97+
let year = prompt('In which year was ECMAScript-2015 specification published?', '');
9898
9999
if (year < 2015) {
100100
alert( 'Too early...' );
@@ -116,8 +116,8 @@ For instance:
116116
117117
```js
118118
//+ run no-beautify
119-
var hasAccess;
120-
var age = prompt('How old are you?', '');
119+
let hasAccess;
120+
let age = prompt('How old are you?', '');
121121
122122
*!*
123123
if (age > 14) {
@@ -136,22 +136,22 @@ The operator is represented by a question mark `"?"`. The formal term "ternary"
136136
137137
The syntax is:
138138
```
139-
var result = condition ? value1 : value2
139+
let result = condition ? value1 : value2
140140
```
141141
142142
The `condition` is evaluated, if it's truthy then `value1` is returned, otherwise -- `value2`.
143143

144144
For example:
145145

146146
```js
147-
var hasAccess = (age > 14) ? true : false;
147+
let hasAccess = (age > 14) ? true : false;
148148
```
149149

150150
We can omit brackets around `age > 14`, because the question mark operator has a low precedence. It executes after comparisons, so:
151151

152152
```js
153153
// the same
154-
var hasAccess = age > 14 ? true : false;
154+
let hasAccess = age > 14 ? true : false;
155155
```
156156

157157
...But brackets make the code more readable. So it's recommended to put them.
@@ -161,7 +161,7 @@ In the described case it is possible to evade the question mark operator, becaus
161161
162162
```js
163163
// the same
164-
var hasAccess = age > 14;
164+
let hasAccess = age > 14;
165165
```
166166
[/smart]
167167
@@ -173,9 +173,9 @@ A sequence of question mark `"?"` operators allows to return a value depending o
173173
For instance:
174174
```js
175175
//+ run
176-
var age = prompt('age?', 18);
176+
let age = prompt('age?', 18);
177177
178-
var message = (age < 3) ? 'Hi, baby!' :
178+
let message = (age < 3) ? 'Hi, baby!' :
179179
(age < 18) ? 'Hello!' :
180180
(age < 100) ? 'Greetings!' :
181181
'What an unusual age!';
@@ -207,7 +207,7 @@ Sometimes the question mark `'?'` is used as a replacement for `if`:
207207

208208
```js
209209
//+ run no-beautify
210-
var company = prompt('Which company created JavaScript?', '');
210+
let company = prompt('Which company created JavaScript?', '');
211211
212212
*!*
213213
(company == 'Netscape') ?
@@ -227,7 +227,7 @@ Here's the same with `if` for comparison:
227227
228228
```js
229229
//+ run no-beautify
230-
var company = prompt('Which company created JavaScript?', '');
230+
let company = prompt('Which company created JavaScript?', '');
231231
232232
*!*
233233
if (company == 'Netscape') {

0 commit comments

Comments
 (0)