Skip to content

Commit b315553

Browse files
author
root
committed
merging all conflicts
2 parents 564a83c + a0266c5 commit b315553

File tree

141 files changed

+796
-741
lines changed

Some content is hidden

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

141 files changed

+796
-741
lines changed

1-js/01-getting-started/1-intro/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Let's see what's so special about JavaScript, what we can achieve with it, and w
66

77
*JavaScript* was initially created to *"make web pages alive"*.
88

9-
The programs in this language are called *scripts*. They can be written right in a web page's HTML and executed automatically as the page loads.
9+
The programs in this language are called *scripts*. They can be written right in a web page's HTML and run automatically as the page loads.
1010

1111
Scripts are provided and executed as plain text. They don't need special preparation or compilation to run.
1212

@@ -70,7 +70,7 @@ Examples of such restrictions include:
7070
There are ways to interact with camera/microphone and other devices, but they require a user's explicit permission. So a JavaScript-enabled page may not sneakily enable a web-camera, observe the surroundings and send the information to the [NSA](https://en.wikipedia.org/wiki/National_Security_Agency).
7171
- Different tabs/windows generally do not know about each other. Sometimes they do, for example when one window uses JavaScript to open the other one. But even in this case, JavaScript from one page may not access the other if they come from different sites (from a different domain, protocol or port).
7272

73-
This is called the "Same Origin Policy". To work around that, *both pages* must contain a special JavaScript code that handles data exchange.
73+
This is called the "Same Origin Policy". To work around that, *both pages* must agree for data exchange and contain a special JavaScript code that handles it. We'll cover that in the tutorial.
7474

7575
This limitation is, again, for the user's safety. A page from `http://anysite.com` which a user has opened must not be able to access another browser tab with the URL `http://gmail.com` and steal information from there.
7676
- JavaScript can easily communicate over the net to the server where the current page came from. But its ability to receive data from other sites/domains is crippled. Though possible, it requires explicit agreement (expressed in HTTP headers) from the remote side. Once again, that's a safety limitation.

1-js/02-first-steps/01-hello-world/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Hello, world!
22

3-
The tutorial that you're reading is about core JavaScript, which is platform-independent. Later on, you'll learn about Node.js and other platforms that use it.
3+
This part of the tutorial is about core JavaScript, the language itself. Later on, you'll learn about Node.js and other platforms that use it.
44

55
But we need a working environment to run our scripts and, since this book is online, the browser is a good choice. We'll keep the amount of browser-specific commands (like `alert`) to a minimum so that you don't spend time on them if you plan to concentrate on another environment (like Node.js). We'll focus on JavaScript in the browser in the [next part](/ui) of the tutorial.
66

@@ -46,7 +46,7 @@ The `<script>` tag contains JavaScript code which is automatically executed when
4646
The `<script>` tag has a few attributes that are rarely used nowadays but can still be found in old code:
4747

4848
The `type` attribute: <code>&lt;script <u>type</u>=...&gt;</code>
49-
: The old HTML standard, HTML4, required a script to have a `type`. Usually it was `type="text/javascript"`. It's not required anymore. Also, the modern HTML standard, HTML5, totally changed the meaning of this attribute. Now, it can be used for JavaScript modules. But that's an advanced topic; we'll talk about modules in another part of the tutorial.
49+
: The old HTML standard, HTML4, required a script to have a `type`. Usually it was `type="text/javascript"`. It's not required anymore. Also, the modern HTML standard, HTML5, totally changed the meaning of this attribute. Now, it can be used for JavaScript modules. But that's an advanced topic; we'll talk about modules in another part of the tutorial.
5050

5151
The `language` attribute: <code>&lt;script <u>language</u>=...&gt;</code>
5252
: This attribute was meant to show the language of the script. This attribute no longer makes sense because JavaScript is the default language. There is no need to use it.

1-js/02-first-steps/04-variables/article.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ alert(message); // Hello world!
136136
```
137137
138138
```smart header="Functional languages"
139-
It's interesting to note that [functional](https://en.wikipedia.org/wiki/Functional_programming) programming languages, like [Scala](http://www.scala-lang.org/) or [Erlang](http://www.erlang.org/), forbid changing variable values.
139+
It's interesting to note that there exist [functional](https://en.wikipedia.org/wiki/Functional_programming) programming languages, like [Scala](http://www.scala-lang.org/) or [Erlang](http://www.erlang.org/) that forbid changing variable values.
140140
141141
In such languages, once the value is stored "in the box", it's there forever. If we need to store something else, the language forces us to create a new box (declare a new variable). We can't reuse the old one.
142142
@@ -182,7 +182,7 @@ let my-name; // hyphens '-' aren't allowed in the name
182182
Variables named `apple` and `AppLE` are two different variables.
183183
```
184184
185-
````smart header="Non-English letters are allowed, but not recommended"
185+
````smart header="Non-Latin letters are allowed, but not recommended"
186186
It is possible to use any language, including cyrillic letters or even hieroglyphs, like this:
187187
188188
```js
@@ -254,7 +254,7 @@ There is a widespread practice to use constants as aliases for difficult-to-reme
254254
255255
Such constants are named using capital letters and underscores.
256256
257-
Like this:
257+
For instance, let's make constants for colors in so-called "web" (hexadecimal) format:
258258
259259
```js run
260260
const COLOR_RED = "#F00";
@@ -290,7 +290,7 @@ In other words, capital-named constants are only used as aliases for "hard-coded
290290
291291
Talking about variables, there's one more extremely important thing.
292292
293-
Please name your variables sensibly. Take time to think about this.
293+
A variable name should have a clean, obvious meaning, describe the data that it stores.
294294
295295
Variable naming is one of the most important and complex skills in programming. A quick glance at variable names can reveal which code was written by a beginner versus an experienced developer.
296296

1-js/02-first-steps/05-types/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ The last three lines may need additional explanation:
226226

227227
## Summary
228228

229-
There are 7 basic types in JavaScript.
229+
There are 7 basic data types in JavaScript.
230230

231231
- `number` for numbers of any kind: integer or floating-point.
232232
- `string` for strings. A string may have one or more characters, there's no separate single-character type.

1-js/02-first-steps/08-comparison/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Why does it dislike zero so much? Always false!
193193
We get these results because:
194194

195195
- Comparisons `(1)` and `(2)` return `false` because `undefined` gets converted to `NaN` and `NaN` is a special numeric value which returns `false` for all comparisons.
196-
- The equality check `(3)` returns `false` because `undefined` only equals `null` and no other value.
196+
- The equality check `(3)` returns `false` because `undefined` only equals `null`, `undefined`, and no other value.
197197

198198
### Evade problems
199199

1-js/02-first-steps/09-alert-prompt-confirm/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Interaction: alert, prompt, confirm
22

3-
This part of the tutorial aims to cover JavaScript "as is", without environment-specific tweaks.
3+
In this part of the tutorial we cover JavaScript language "as is", without environment-specific tweaks.
44

55
But we'll still be using the browser as our demo environment, so we should know at least a few of its user-interface functions. In this chapter, we'll get familiar with the browser functions `alert`, `prompt` and `confirm`.
66

1-js/02-first-steps/10-ifelse/article.md

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

33
Sometimes, we need to perform different actions based on different conditions.
44

5-
To do that, we use the `if` statement and the conditional (ternary) operator which we will be referring to as the “question mark operator `?` for simplicity.
5+
To do that, we can use the `if` statement and the conditional operator `?`, that's also called a "question mark" operator.
66

77
## The "if" statement
88

@@ -103,7 +103,7 @@ In the code above, JavaScript first checks `year < 2015`. If that is falsy, it g
103103

104104
There can be more `else if` blocks. The final `else` is optional.
105105

106-
## Ternary operator '?'
106+
## Conditional operator '?'
107107

108108
Sometimes, we need to assign a variable depending on a condition.
109109

@@ -124,9 +124,9 @@ if (age > 18) {
124124
alert(accessAllowed);
125125
```
126126

127-
The so-called "ternary" or "question mark" operator lets us do that in a shorter and simpler way.
127+
The so-called "conditional" or "question mark" operator lets us do that in a shorter and simpler way.
128128

129-
The operator is represented by a question mark `?`. The formal term "ternary" means that the operator has three operands. It is actually the one and only operator in JavaScript which has that many.
129+
The operator is represented by a question mark `?`. Sometimes it's called "ternary", because the operator has three operands. It is actually the one and only operator in JavaScript which has that many.
130130

131131
The syntax is:
132132
```js
@@ -141,7 +141,7 @@ For example:
141141
let accessAllowed = (age > 18) ? true : false;
142142
```
143143

144-
Technically, we can omit the parentheses around `age > 18`. The question mark operator has a low precedence, so it executes after the comparison `>`.
144+
Technically, we can omit the parentheses around `age > 18`. The question mark operator has a low precedence, so it executes after the comparison `>`.
145145

146146
This example will do the same thing as the previous one:
147147

1-js/02-first-steps/11-logical-operators/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ The OR `||` operator does the following:
8484

8585
A value is returned in its original form, without the conversion.
8686

87-
In other words, a chain of OR `"||"` returns the first truthy value or the last one if no such value is found.
87+
In other words, a chain of OR `"||"` returns the first truthy value or the last one if no truthy value is found.
8888

8989
For instance:
9090

@@ -101,7 +101,7 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl
101101

102102
1. **Getting the first truthy value from a list of variables or expressions.**
103103

104-
Imagine we have several variables which can either contain data or be `null/undefined`. How can we find the first one with data?
104+
Imagine we have a list of variables which can either contain data or be `null/undefined`. How can we find the first one with data?
105105

106106
We can use OR `||`:
107107

@@ -143,7 +143,7 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl
143143
alert(x); // 1
144144
```
145145

146-
An assignment is a simple case. Other side effects can also be involved.
146+
An assignment is a simple case. There may be side effects, that won't show up if the evaluation doesn't reach them.
147147

148148
As we can see, such a use case is a "shorter way of doing `if`". The first operand is converted to boolean. If it's false, the second one is evaluated.
149149

1-js/02-first-steps/12-while-for/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ while (i) { // when i becomes 0, the condition becomes falsy, and the loop stops
4747
}
4848
```
4949

50-
````smart header="Brackets are not required for a single-line body"
51-
If the loop body has a single statement, we can omit the brackets `{…}`:
50+
````smart header="Curly braces are not required for a single-line body"
51+
If the loop body has a single statement, we can omit the curly braces `{…}`:
5252
5353
```js run
5454
let i = 3;

1-js/02-first-steps/14-function-basics/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ showMessage();
101101
alert( userName ); // *!*Bob*/!*, the value was modified by the function
102102
```
103103

104-
The outer variable is only used if there's no local one. So an occasional modification may happen if we forget `let`.
104+
The outer variable is only used if there's no local one.
105105

106106
If a same-named variable is declared inside the function then it *shadows* the outer one. For instance, in the code below the function uses the local `userName`. The outer one is ignored:
107107

@@ -128,7 +128,7 @@ Variables declared outside of any function, such as the outer `userName` in the
128128
129129
Global variables are visible from any function (unless shadowed by locals).
130130
131-
Usually, a function declares all variables specific to its task. Global variables only store project-level data, and it's important that these variables are accessible from anywhere. Modern code has few or no globals. Most variables reside in their functions.
131+
It's a good practice to minimize the use of global variables. Modern code has few or no globals. Most variables reside in their functions. Sometimes though, they can be useful to store project-level data.
132132
```
133133

134134
## Parameters
@@ -376,7 +376,7 @@ A few examples of breaking this rule:
376376
- `createForm` -- would be bad if it modifies the document, adding a form to it (should only create it and return).
377377
- `checkPermission` -- would be bad if it displays the `access granted/denied` message (should only perform the check and return the result).
378378

379-
These examples assume common meanings of prefixes. What they mean for you is determined by you and your team. Maybe it's pretty normal for your code to behave differently. But you should have a firm understanding of what a prefix means, what a prefixed function can and cannot do. All same-prefixed functions should obey the rules. And the team should share the knowledge.
379+
These examples assume common meanings of prefixes. You and your team are free to agree on other meanings, but usually they're not much different. In any case, you should have a firm understanding of what a prefix means, what a prefixed function can and cannot do. All same-prefixed functions should obey the rules. And the team should share the knowledge.
380380
```
381381

382382
```smart header="Ultrashort function names"

0 commit comments

Comments
 (0)