You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/1-getting-started/3-devtools/article.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,11 +8,11 @@ But in the browser, a user doesn't see the errors by default. So, if something g
8
8
9
9
To see errors and get a lot of other useful information about scripts, browsers have embedded "developer tools".
10
10
11
-
**It is recommended to use Chrome or Firefox for the development.**
11
+
**Most often developers lean towards Chrome or Firefox for the development.**
12
12
13
13
Other browsers also provide developer tools, but are usually in a "catching-up" position, compared to Chrome/Firefox which are the best.
14
14
15
-
If there is an error in the certain browser only, then we can use it's developer tools, but usually -- Chrome/Firefox.
15
+
If there is an error in the certain browser only, then we can always switch to it's developer tools for the concrete problem.
16
16
17
17
Developer tools are really powerful, there are many features. On this stage let's just look how to open them, look at errors and run JavaScript commands.
Copy file name to clipboardExpand all lines: 1-js/2-first-steps/01-hello-world/article.md
+8-1Lines changed: 8 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,18 @@
1
1
# Hello, world!
2
2
3
-
In this chapter we'll create a simple script and see it working.
3
+
About 98% of the tutorial is core Javascript, that is platform-independant. So you'll be able to learn how to use Node.JS and other things based on that knowledge.
4
+
5
+
But we need something like a "base environment" to run our scripts, and browser is probably a good choice.
6
+
7
+
So we'll start with attaching a script to the webpage. For other environments like Node.JS there are other ways to run it.
4
8
5
9
[cut]
6
10
11
+
[todo remove defer/async from here and move to 2nd part?]
12
+
7
13
## The "script" tag
8
14
15
+
[todo need this? and special (need it too?)]
9
16
```smart header="What if I want to move faster?"
10
17
In the case if you've developed with JavaScript already or have a lot of experience in another language, you can skip detailed explanatins and jump to <info:javascript-specials>. There you can find an essense of important features.
Copy file name to clipboardExpand all lines: 1-js/2-first-steps/03-structure/article.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ The first overall thing to know is the code structure.
6
6
7
7
## Statements
8
8
9
-
The code consists of [statements](https://en.wikipedia.org/wiki/Statement_(computer_science))-- syntax constructs and commands to perform actions.
9
+
[Statements](https://en.wikipedia.org/wiki/Statement_(computer_science))are syntax constructs and commands to perform actions.
10
10
11
11
We've already seen a statement `alert('Hello, world!')`, which shows the message.
12
12
@@ -36,9 +36,9 @@ alert( 'Hello' )
36
36
alert( 'World' )
37
37
```
38
38
39
-
In this case JavaScript interprets the line break as a splitter. Just as if there were a semicolon between the lines.
39
+
Here JavaScript interprets the line break as an "implicit" semicolon. That's also called an [automatic semicolon insertion](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion).
40
40
41
-
**But it's important that "in most cases" does not mean "always"!**
41
+
**In most cases a newline implies a simicolon. But "in most cases" does not mean "always"!**
42
42
43
43
There are cases when a newline does not mean a semicolon, for example:
44
44
@@ -50,22 +50,22 @@ alert(3 +
50
50
51
51
The code outputs `6`, because JavaScript does not insert semicolons here. It is intuitively obvious that if the line ends with a plus `"+"`, then it is an "incomplete expression". And in this case that's actually fine and comfortable.
52
52
53
-
**But there are situations where JavaScript "fails" to assume a semicolon break where it is really needed.**
53
+
**But there are situations where JavaScript "fails" to assume a semicolon where it is really needed.**
54
54
55
55
Errors which come appear in such cases are quite hard to find and fix.
56
56
57
57
````smart header="An example of the error"
58
-
For a curious reader who might be interested in a concrete example, check this code out:
58
+
If you're curious to see a concrete example, check this code out:
59
59
60
60
```js run
61
61
[1, 2].forEach(alert)
62
62
```
63
63
64
64
It shows `1` then `2`.
65
65
66
-
No need to think about the meaning of the brackets `[]` and `forEach` just for now -- it does not matter here. Let's just remember the result.
66
+
No need to think about the meaning of the brackets `[]` and `forEach`, for now -- it does not matter. Let's just remember the result.
67
67
68
-
Now we prepend an `alert` statement *not followed by a semicolon*:
68
+
Now we prepend the code with an `alert` statement *not followed by a semicolon*:
69
69
70
70
```js run no-beautify
71
71
alert( "There will be an error" ) // shown
@@ -77,16 +77,16 @@ Now if we run it, only the first `alert` is shown, and then an error.
77
77
But everything's fine if we add a semicolon:
78
78
```js run
79
79
alert( "All fine now" ); // shown
80
-
[1, 2].forEach(alert) // then this too
80
+
[1, 2].forEach(alert) // this works too
81
81
```
82
82
83
-
The error in the former variant occurs because JavaScript engine does not assume a semicolon before square brackets `[...]`, so the code is actually treated as a one-line statement:
83
+
The error in the no-semicolon variant occurs because JavaScript engine does not assume a semicolon before square brackets `[...]`, so the code is actually treated as a one-line statement:
84
84
85
85
```js run no-beautify
86
86
alert( "There will be an error" )[1, 2].forEach(alert)
87
87
```
88
88
89
-
And in this particular case, that's just wrong. Hence the error.
89
+
And in this particular case, that's just wrong. There must be two independent statements. Hence the error.
90
90
91
91
````
92
92
@@ -154,5 +154,5 @@ Please, don't hesitate to comment your code.
154
154
155
155
Comments increase the overall code footprint, but that's not a problem at all. There are many tools which minify the code before publishing to production server. They remove comments, so they do not appear in the working scripts. So, the comments do not have any negative effects on production at all.
156
156
157
-
Further in the tutorial we'll make more notes about how to write the code better, easier to read and maintain. We'll also talk more about comments.
157
+
Further in the tutorial we'll devote a special chapter to code style, also explaining how to write better comments.
Copy file name to clipboardExpand all lines: 1-js/2-first-steps/04-strict-mode/article.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,10 +58,10 @@ Looking ahead let's just note that `"use strict"` can be put at the start of a f
58
58
59
59
It is recommended to always start a script with `"use strict"`, for the following reasons:
60
60
61
-
1. First, because all modern browsers support it, except Internet Explorer 9 and lower.
61
+
1. First, all modern browsers support it. Only outdated ones like Internet Explorer 9 and below do not.
62
62
2. Second, the modern JavaScript actually forces us into the strict mode. There are several modern language features like "classes" and "modules" that enable strict mode automatically. So, it's hard to evade it.
63
63
64
-
Here in the tutorial all code (except where said otherwise) works in `"use strict"`. but we'll still note the subtle differences of what happens if you forget it or if the visitor has an outdated browser. So you will also be able to write a code for IE8 and below if you'd like that.
64
+
Here in the tutorial all code (except where said otherwise) works in `"use strict"`. but we'll still note the subtle differences of what happens if you forget it or if the visitor has an outdated browser. So you will also be able to write a code that also works for old IE if you'd like that.
We generally use upper case for constants that are "hard-coded" or, in other words, when the value is directly written into the code.
1
+
We generally use upper case for constants that are "hard-coded". Or, in other words, when the value is known prior to execution and directly written into the code.
2
2
3
-
In this code, `birthday` is just like that. So we could use the upper case for it.
3
+
In this code, `birthday` is exactly like that. So we could use the upper case for it.
4
4
5
-
In contrast, `age` is evaluated in run-time. Today we have one age, a year after we'll have another one. It is constant in a sense that it does not change through the code execution. But it is a bit "less of a constant" than `birthday`, so we should keep the lower case for it.
5
+
In contrast, `age` is evaluated in run-time. Today we have one age, a year after we'll have another one. It is constant in a sense that it does not change through the code execution. But it is a bit "less of a constant" than `birthday`, it is calculated, so we should keep the lower case for it.
Copy file name to clipboardExpand all lines: 1-js/2-first-steps/05-variables/3-uppercast-constant/task.md
+5-7Lines changed: 5 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,18 +9,16 @@ Examine the following code:
9
9
```js
10
10
constbirthday='18.04.1982';
11
11
12
-
constage=calculateAgeBasedOn(birthday);
12
+
constage=someCode(birthday);
13
13
```
14
14
15
-
Here we have a constant `birthday` date and the `age` is calculated with the help of a function (its code is not provided cause it doesn't matter here).
15
+
Here we have a constant `birthday` date and the `age` is calculated from `birthday`with the help of some code (it is not provided for shortness, and because details don't matter here).
16
16
17
-
Would it be right to name both constants using the upper case? Like this:
17
+
Would it be right to use upper case for `birthday`? For `age`? Or even for both?
18
18
19
19
```js
20
-
constBIRTHDAY='18.04.1982';
20
+
constBIRTHDAY='18.04.1982';// make uppercase?
21
21
22
-
constAGE=calculateAgeBasedOn(BIRTHDAY);
22
+
constAGE=someCode(BIRTHDAY);// make uppercase?
23
23
```
24
24
25
-
...Or we should use the upper case for only one of them? Or just use lower case everywhere?
Copy file name to clipboardExpand all lines: 1-js/2-first-steps/05-variables/article.md
+29-13Lines changed: 29 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,16 @@
1
1
# Variables
2
2
3
-
Most of the time, script needs to work with the information.
3
+
Most of the time, a script needs to work with the information.
4
4
5
-
If it's an online-shop -- that's going to be the goods and a shopping cart. If it's a chat -- visitors, messages and so on.
5
+
If it's an online-shop -- that's going to be the goods and a shopping cart. If it's a chat -- users, messages and so on.
6
6
7
7
Variables are used to store the information.
8
8
9
9
[cut]
10
10
11
11
## A variable
12
12
13
-
A [variable]("https://en.wikipedia.org/wiki/Variable_(computer_science)") is defined as a "named storage" for the information. We can use variables to store the goods, visitors etc.
13
+
A [variable]("https://en.wikipedia.org/wiki/Variable_(computer_science)") is a basic "named storage" for the information. We can use variables to store the goods, visitors etc.
14
14
15
15
To create a variable in JavaScript, we need to use the `let` keyword.
16
16
@@ -30,7 +30,7 @@ message = 'Hello'; // store the string
30
30
*/!*
31
31
```
32
32
33
-
The string is now saved into the memory area assosiated with that variable. We can access it using the variable name:
33
+
The string is now saved into the memory area assosiated with the variable. We can access it using the variable name:
When a programmer is sure that the variable should never change, he can use `const` to guarantee it, and also to clearly show that fact to everyone.
232
251
233
252
234
-
### Uppercases constants
253
+
### Uppercase constants
235
254
236
-
There is a widespread practice to use constants as aliases for difficult-to-remember and hard-coded prior to execution values.
255
+
There is a widespread practice to use constants as aliases for difficult-to-remember values that are known prior to execution.
237
256
238
257
Such constants are named using capitals and underscores.
239
258
@@ -250,10 +269,7 @@ let color = COLOR_ORANGE;
250
269
alert( color ); // #FF7F00
251
270
```
252
271
253
-
`COLOR_ORANGE` is much easier to understand and remember than `"#FF7F00"`. Also it is much easier to make a typo in `"#FF7F00"` than in `COLOR_ORANGE`.
254
-
255
-
The upper case is only used for constants that are "hard-coded" (written in the code before its execution).
256
-
272
+
`COLOR_ORANGE` is much easier to remember than `"#FF7F00"`. Also it is much easier to mistype in `"#FF7F00"` than in `COLOR_ORANGE`. And when reading the code -- `COLOR_ORANGE` is much more meaningful.
0 commit comments