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/01-getting-started/1-intro/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
@@ -6,7 +6,7 @@ Let's see what's so special about JavaScript, what we can achieve with it, and w
6
6
7
7
*JavaScript* was initially created to *"make web pages alive"*.
8
8
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.
10
10
11
11
Scripts are provided and executed as plain text. They don't need special preparation or compilation to run.
12
12
@@ -70,7 +70,7 @@ Examples of such restrictions include:
70
70
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).
71
71
- 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).
72
72
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.
74
74
75
75
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.
76
76
- 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.
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.
140
140
141
141
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.
142
142
@@ -182,7 +182,7 @@ let my-name; // hyphens '-' aren't allowed in the name
182
182
Variables named `apple` and `AppLE` are two different variables.
183
183
```
184
184
185
-
````smart header="Non-English letters are allowed, but not recommended"
185
+
````smart header="Non-Latin letters are allowed, but not recommended"
186
186
It is possible to use any language, including cyrillic letters or even hieroglyphs, like this:
187
187
188
188
```js
@@ -254,7 +254,7 @@ There is a widespread practice to use constants as aliases for difficult-to-reme
254
254
255
255
Such constants are named using capital letters and underscores.
256
256
257
-
Like this:
257
+
For instance, let's make constants for colors in so-called "web" (hexadecimal) format:
258
258
259
259
```js run
260
260
const COLOR_RED = "#F00";
@@ -290,7 +290,7 @@ In other words, capital-named constants are only used as aliases for "hard-coded
290
290
291
291
Talking about variables, there's one more extremely important thing.
292
292
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.
294
294
295
295
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.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/09-alert-prompt-confirm/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Interaction: alert, prompt, confirm
2
2
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.
4
4
5
5
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`.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/10-ifelse/article.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
Sometimes, we need to perform different actions based on different conditions.
4
4
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.
6
6
7
7
## The "if" statement
8
8
@@ -103,7 +103,7 @@ In the code above, JavaScript first checks `year < 2015`. If that is falsy, it g
103
103
104
104
There can be more `else if` blocks. The final `else` is optional.
105
105
106
-
## Ternary operator '?'
106
+
## Conditional operator '?'
107
107
108
108
Sometimes, we need to assign a variable depending on a condition.
109
109
@@ -124,9 +124,9 @@ if (age > 18) {
124
124
alert(accessAllowed);
125
125
```
126
126
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.
128
128
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.
130
130
131
131
The syntax is:
132
132
```js
@@ -141,7 +141,7 @@ For example:
141
141
let accessAllowed = (age >18) ?true:false;
142
142
```
143
143
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 `>`.
145
145
146
146
This example will do the same thing as the previous one:
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/11-logical-operators/article.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,7 +84,7 @@ The OR `||` operator does the following:
84
84
85
85
A value is returned in its original form, without the conversion.
86
86
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.
88
88
89
89
For instance:
90
90
@@ -101,7 +101,7 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl
101
101
102
102
1.**Getting the first truthy value from a list of variables or expressions.**
103
103
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?
105
105
106
106
We can use OR `||`:
107
107
@@ -143,7 +143,7 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl
143
143
alert(x); // 1
144
144
```
145
145
146
-
An assignment is a simple case. Otherside 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.
147
147
148
148
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.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/14-function-basics/article.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,7 +101,7 @@ showMessage();
101
101
alert( userName ); // *!*Bob*/!*, the value was modified by the function
102
102
```
103
103
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.
105
105
106
106
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:
107
107
@@ -128,7 +128,7 @@ Variables declared outside of any function, such as the outer `userName` in the
128
128
129
129
Global variables are visible from any function (unless shadowed by locals).
130
130
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.
132
132
```
133
133
134
134
## Parameters
@@ -376,7 +376,7 @@ A few examples of breaking this rule:
376
376
- `createForm` -- would be bad if it modifies the document, adding a form to it (should only create it and return).
377
377
- `checkPermission` -- would be bad if it displays the `access granted/denied` message (should only perform the check and return the result).
378
378
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.
Copy file name to clipboardExpand all lines: 1-js/03-code-quality/06-polyfills/article.md
+7-10Lines changed: 7 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,21 +19,20 @@ Here Babel comes to the rescue.
19
19
20
20
Actually, there are two parts in Babel:
21
21
22
-
1. First, the transpiler program, which rewrites the code. The developer runs it on their own computer. It rewrites the code into the older standard. And then the code is delivered to the website for users. Modern project build system like [webpack](http://webpack.github.io/)or [brunch](http://brunch.io/)provide means to run transpiler automatically on every code change, so that doesn't involve any time loss from our side.
22
+
1. First, the transpiler program, which rewrites the code. The developer runs it on their own computer. It rewrites the code into the older standard. And then the code is delivered to the website for users. Modern project build system like [webpack](http://webpack.github.io/) provide means to run transpiler automatically on every code change, so that very easy to integrate into development process.
23
23
24
24
2. Second, the polyfill.
25
25
26
-
The transpiler rewrites the code, so syntax features are covered. But for new functions we need to write a special script that implements them. JavaScript is a highly dynamic language, scripts may not just add new functions, but also modify built-in ones, so that they behave according to the modern standard.
26
+
New language features may include new built-in functions and syntax constructs.
27
+
The transpiler rewrites the code, transforming syntax constructs into older ones. But as for new built-in functions, we need to implement them. JavaScript is a highly dynamic language, scripts may add/modify any functions, so that they behave according to the modern standard.
27
28
28
-
There's a term "polyfill" for scripts that "fill in" the gap and add missing implementations.
29
+
A script that updates/adds new functions is called "polyfill". It "fills in" the gap and adds missing implementations.
29
30
30
31
Two interesting polyfills are:
31
32
-[babel polyfill](https://babeljs.io/docs/usage/polyfill/) that supports a lot, but is big.
32
33
-[polyfill.io](http://polyfill.io) service that allows to load/construct polyfills on-demand, depending on the features we need.
33
34
34
-
So, we need to setup the transpiler and add the polyfill for old engines to support modern features.
35
-
36
-
If we orient towards modern engines and do not use features except those supported everywhere, then we don't need to use Babel.
35
+
So, if we're going to use modern language features, a transpiler and a polyfill are necessary.
37
36
38
37
## Examples in the tutorial
39
38
@@ -49,9 +48,7 @@ Examples that use modern JS will work only if your browser supports it.
49
48
````
50
49
51
50
```offline
52
-
As you're reading the offline version, examples are not runnable. But they usually work :)
51
+
As you're reading the offline version, in PDF examples are not runnable. In EPUB some of them can run.
53
52
```
54
53
55
-
[Chrome Canary](https://www.google.com/chrome/browser/canary.html) is good for all examples, but other modern browsers are mostly fine too.
56
-
57
-
Note that on production we can use Babel to translate the code into suitable for less recent browsers, so there will be no such limitation, the code will run everywhere.
54
+
Google Chrome is usually the most up-to-date with language features, good to run bleeding-edge demos without any transpilers, but other modern browsers also work fine.
0 commit comments