Skip to content

Commit 51edbb1

Browse files
committed
minor fixes
1 parent 06cdd5b commit 51edbb1

File tree

3 files changed

+73
-47
lines changed

3 files changed

+73
-47
lines changed

1-js/01-getting-started/01-hello-javascript/article.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
11
# Hello, JavaScript!
22

3-
The programs in JavaScript are called *scripts*. They can be embedded right into HTML using `<script>` tag and run automatically as the page loads.
3+
JavaScript has a rich history.
44

5-
For example, this HTML-page shows the "Hello" message:
5+
It was created in 1995 as a simple language exclusively for web browsers, to “make web pages alive”. Since then it has greatly evolved.
66

7-
```html run
7+
Today we can use JavaScript on many platforms:
8+
9+
- In a web-browser, by embedding it into a web page.
10+
- On a general purpose computer or a server, using [Node.js](https://nodejs.org) and other means.
11+
- ...Or actually on any device that has a special piece of software, called "JavaScript engine".
12+
13+
Technically, even a coffee machine can include its own JavaScript engine to allow programming of coffee recipes.
14+
15+
![](javascript-engine.svg)
16+
17+
There's a formal language description called [ECMAScript Language Specification](https://tc39.es/ecma262/), it describes how a JavaScript engine works. Sometimes we'll give references to it, but, though technically strict, it's hard to read for humans. At least at first.
18+
19+
Programs in JavaScript are called *scripts*.
20+
21+
Browsers have built-in JavaScript engines, so they can run scripts. They can be embedded right into HTML using the `<script>` tag and run automatically as the page loads.
22+
23+
For example, this HTML-page shows the "Hello, world!" message:
24+
25+
```html run height=0
826
<!doctype html>
927
<script>
1028
alert("Hello, world!");
1129
</script>
1230
```
1331

14-
JavaScript can execute not only in a browser, but also on a server, or actually on any device that has a special program called [the JavaScript engine](https://en.wikipedia.org/wiki/JavaScript_engine).
15-
16-
Browsers have built-in JavaScript engines, so they can run scripts.
17-
18-
We can also run scripts using [Node.js](https://nodejs.org), it's commonly used to build server-side applications.
32+
To see it in action, you can click the "run" button in the upper-right corner. Also you can create a new file, e.g. `my.html` with this text and open it locally in a browser.
1933

2034
Depending on the environment, JavaScript may provide platform-specific functionality.
2135

22-
- In a web browser, JavaScript can manipulate the web-page, send network requests, show messages and so on.
36+
- In a browser, JavaScript can manipulate the web-page, send network requests, show messages and so on.
2337
- In node.js we can use JavaScript to run a web-server, read and write arbitrary files.
2438
- ...And so on.
2539

26-
Technically, even a coffee machine can include its own JavaScript engine, to allow programming of coffee recipes.
27-
28-
![](javascript-engine.svg)
29-
30-
**In this tutorial we concentrate on the "core JavaScript", that's the same everywhere.**
40+
**In this course we concentrate on the core JavaScript, that's the same everywhere.**
3141

3242
We'll try to keep browser-specific notes at minimum. After you learn the core, you can go in any direction: browsers, frameworks, servers and so on.
3343

1-js/01-getting-started/02-basics/article.md

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

44
## Statements
55

6-
Statements are syntax constructs and commands that perform actions, make JavaScript "do" something.
6+
Just like a human speech consists of sentences, JavaScript code consists of *statements*.
7+
8+
Statements are commands and syntax constructs that perform actions, "do" something.
79

810
Here's an example of a statement:
911

@@ -17,7 +19,7 @@ We can have as many statements in our code as we want.
1719

1820
Statements can be separated with a semicolon.
1921

20-
For example, here we split "Hello World" into two alerts:
22+
For example, we can split "Hello World" into two messages, one after the other:
2123

2224
```js run no-beautify
2325
alert("Hello"); alert("World");
@@ -30,33 +32,35 @@ alert("Hello");
3032
alert("World");
3133
```
3234

33-
## Semicolons..or not?
35+
### Semicolons..or not?
3436

35-
A semicolon may be omitted in most cases when a line break exists.
37+
A semicolon may be omitted in most cases when a line break exists beween statements.
3638

37-
This would also work:
39+
This code is the same as above, just without semicolons:
3840

3941
```js run no-beautify
4042
alert("Hello")
4143
alert("World")
4244
```
4345

44-
Usually, JavaScript interprets the line break as an "implicit" semicolon. This is called an [automatic semicolon insertion](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion).
46+
It also works, because usually JavaScript interprets a line break as an "implicit" semicolon. This is called an "automatic semicolon insertion".
4547

46-
But there are exceptions, like this:
48+
There are exceptions for that rule, for example:
4749

4850
```js run no-beautify
4951
alert(1 +
5052
2);
5153
```
5254

53-
The code outputs `3` because JavaScript does not insert semicolons after the plus `+`. It is intuitively obvious that if the line ends with a plus `"+"`, then it is an incomplete expression, that's continued on the next line. And in this case that works as intended.
55+
This code outputs `3`, same as a single-line `alert(1 + 2)`. Here JavaScript does not treat the line-break after `+` as the end of the statement.
56+
57+
Why so? It's intuitively obvious that if the line ends with a plus `+`, then the expression is incomplete and will be continued on the next line. JavaScript "understands" that too. And in this case that works as intended.
5458

5559
**But there are situations where our intuition differs from JavaScript auto-insertion rules.**
5660

5761
That may lead to subtle errors.
5862

59-
````spoiler header="Read more about it"
63+
````spoiler header="See an example of such error"
6064
6165
If you're curious to see a concrete example of such an error, check this code out:
6266
@@ -96,19 +100,19 @@ alert("There will be an error")[1, 2].forEach(alert)
96100
But such a merge in this case is just wrong, hence the error. This can happen in other situations as well.
97101
````
98102

99-
To prevent such errors, we recommend putting semicolons between statements even if they are separated by newlines. This rule is widely adopted by the community.
103+
To prevent such errors, we recommend putting semicolons between statements, even if they are separated by newlines.
100104

101-
Let's note once again -- *it is possible* to leave out semicolons most of the time. But it's safer -- especially for a beginner -- to use them.
105+
Let's note once again -- *it is possible* to leave out semicolons most of the time. But it's safer, especially for a beginner, to use them.
102106

103107
## Comments
104108

105109
As time goes on, programs become more and more complex. It becomes necessary to add *comments* which describe what the code does and why.
106110

107111
Comments can be put into any place of a script. They don't affect its execution because the engine simply ignores them.
108112

109-
**One-line comments start with two forward slash characters `//`.**
113+
**One-line comments start with two forward slash characters `//`. The rest of the line is a comment.**
110114

111-
The rest of the line is a comment. It may occupy a full line of its own or follow a statement.
115+
Such comment may occupy a full line of its own or follow a statement.
112116

113117
Like here:
114118
```js run
@@ -118,6 +122,8 @@ alert("Hello");
118122
alert("World"); // This comment follows the statement
119123
```
120124

125+
For longer, descriptive comments that span multiple lines, we can use the `/* ... */` syntax.
126+
121127
**Multiline comments start with a forward slash and an asterisk <code>/&#42;</code> and end with an asterisk and a forward slash <code>&#42;/</code>.**
122128

123129
Like this:
@@ -130,9 +136,9 @@ alert("Hello");
130136
alert("World");
131137
```
132138

133-
The content of comments is ignored, so if we put code inside <code>/&#42; ... &#42;/</code>, it won't execute.
139+
The content of comments is ignored, so if we wrap a piece of code into `/* ... */`, it won't execute.
134140

135-
Sometimes it can be handy to temporarily disable a part of code:
141+
It can be handy to temporarily disable a part of code:
136142

137143
```js run
138144
/* Commenting out the code
@@ -142,7 +148,9 @@ alert("World");
142148
```
143149

144150
```smart header="Use hotkeys!"
145-
In most editors, a line of code can be commented out by pressing the `key:Ctrl+/` hotkey for a single-line comment and something like `key:Ctrl+Shift+/` -- for multiline comments (select a piece of code and press the hotkey). For Mac, try `key:Cmd` instead of `key:Ctrl` and `key:Option` instead of `key:Shift`.
151+
In most editors, a line of code can be commented out by pressing the `key:Ctrl+/` hotkey for a single-line comment and something like `key:Ctrl+Shift+/` -- for multiline comments (select a piece of code and press the hotkey).
152+
153+
For Mac, try `key:Cmd` instead of `key:Ctrl` and `key:Option` instead of `key:Shift`.
146154
```
147155

148156
````warn header="Nested comments are not supported!"
@@ -152,7 +160,7 @@ Such code will die with an error:
152160
153161
```js run no-beautify
154162
/*
155-
/* nested comment ?!? */
163+
/* nested comment leads to an error! */
156164
*/
157165
alert( "World" );
158166
```
@@ -164,24 +172,26 @@ Comments increase the overall code footprint, but that's not a problem at all. T
164172

165173
## Strict mode
166174

167-
JavaScript appeared many years ago, in 1995. Then ,for a long time, it evolved without compatibility issues. New features were added to the language while old functionality didn't change.
175+
JavaScript appeared in 1995 as a simple, browser-only language. Then, for a long time, it evolved without compatibility issues. New features were added to the language while old functionality didn't change.
168176

169-
That had the benefit of never breaking existing code. But the downside was that any mistake or an imperfect decision made by JavaScript's creators got stuck in the language forever.
177+
That had the benefit of never breaking existing code. But the downside was that any mistake or an imperfect decision made by JavaScript creators got stuck in the language forever.
170178

171179
This was the case until 2009, when the 5th version of the standard appeared. It added new features to the language and modified some of the existing ones.
172180

173-
Now the important part.
181+
Now the important part about it.
182+
183+
**To keep the old code working, the newer 2009+ modifications are off by default.**
174184

175-
**To keep the old code working, these newer modifications are off by default.**
185+
Yes, a lot of time has passed, but still it's so.
176186

177187
We need to explicitly enable them with a special directive: `"use strict"`
178188

179-
With that directive on top the script runs in so-called "strict mode". Or, we'd better say "modern mode", because that's what it essentially is.
189+
A script with the `"use strict"` directive on top runs in so-called "strict mode". Or we'd better say "modern mode", because that's what it essentially is.
180190

181191
![](use-strict.svg)
182192

183193
Some JavaScript features enable strict mode automatically, e.g. classes and modules, so that we don't need to write `"use strict"` for them. We'll cover these features later.
184194

185195
**Here, in the tutorial, we'll always use strict mode, unless explicitly stated otherwise.**
186196

187-
We're studying modern JavaScript after all. But you'll also see notes about how things work without `use strict`, just in case you come across an old script.
197+
We're studying modern JavaScript after all. But you'll also see notes about how things work without `use strict`, just in case you forget to put that directive or meet a script without it.

1-js/01-getting-started/03-variables/article.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
# Variables
22

3-
Most of the time, a JavaScript application needs to work with information. Here are two examples:
4-
1. An online shop -- the information might include goods being sold and a shopping cart.
5-
2. A chat application -- the information might include users, messages, and much more.
3+
To do its job, our code needs needs to store and process information.
4+
5+
The exact kind of information depends on the application.
6+
7+
For example:
8+
9+
- An online shop -- the information includes goods being sold and a shopping cart.
10+
- A chat application -- the information includes users, messages, etc.
611

712
Variables are used to store this information.
813

914
## A variable
1015

11-
A [variable](https://en.wikipedia.org/wiki/Variable_(computer_science)) is a "named storage" for data. We can use variables to store goodies, visitors, and other data.
16+
A [variable](https://en.wikipedia.org/wiki/Variable_(computer_science)) is a "named storage" for data. We can use variables to store goods, visitors and so on.
1217

1318
To create a variable in JavaScript, use the `let` keyword.
1419

15-
The statement below creates (in other words: *declares*) a variable with the name "message":
20+
The statement below creates (in formal terms: *declares*) a variable with the name "message":
1621

1722
```js
1823
let message;
1924
```
2025

21-
Now, we can put some data into it by using the assignment `=`:
26+
Now we can put some data into it by using the assignment `=`:
2227

2328
```js
2429
let message;
2530

2631
*!*
27-
message = "Hello"; // store the string
32+
message = "Hello"; // store the string "Hello"
2833
*/!*
2934
```
3035

@@ -42,7 +47,7 @@ alert(message); // shows the variable content
4247
To be concise, we can combine the variable declaration and assignment into a single line:
4348

4449
```js run
45-
let message = "Hello!"; // define the variable and assign the value
50+
let message = "Hello!"; // define the variable and assign the value to it
4651

4752
alert(message); // Hello!
4853
```
@@ -153,7 +158,7 @@ let message = "Two"; // SyntaxError: 'message' has already been declared
153158
So, we should declare a variable once and then refer to it without `let`.
154159
````
155160

156-
````warn header="Without `use strict` it's possible to assign to an undeclared variable"
161+
````warn header="Without `use strict`: it's possible to assign to an undeclared variable"
157162
Normally, we need to define a variable before using it. But in the old times, it was technically possible to create a variable by a mere assignment of the value without using `let`.
158163

159164
This still works now, without strict mode:
@@ -175,8 +180,9 @@ This is a bad practice and would cause an error in strict mode:
175180
num = 5; // error: num is not defined
176181
*/!*
177182
```
178-
````
179183

184+
We provide details about how things work without `use strict` just to make sure you won't be surprised by such scripts. Luckily, there aren't many differences. As said before, we should always be in the strict mode.
185+
````
180186
181187
### Variable naming
182188

0 commit comments

Comments
 (0)