commit
f423a00e24
12 changed files with 15 additions and 16 deletions
|
@ -61,7 +61,7 @@ Comments before and after scripts.
|
|||
//--></script>
|
||||
```
|
||||
|
||||
These comments were supposed to hide the code from an old browser that didn't know about a `<script>` tag. But all browsers born in the past 15+ years don't have any issues. We mention it here, because such comments serve as a sign. If you see that somewhere -- that code is probably really old and not worth looking into.
|
||||
This trick isn't used in modern JavaScript. These comments were used to hide the JavaScript code from old browsers that didn't know about a `<script>` tag. Since browsers born in the last 15 years don't have this issue, this kind of comment can help you identify really old code.
|
||||
|
||||
|
||||
## External scripts
|
||||
|
|
|
@ -176,7 +176,7 @@ Yeah, mathematically that's strange. The last result states that "`null` is grea
|
|||
|
||||
The reason is that an equality check `==` and comparisons `> < >= <=` work differently. Comparisons convert `null` to a number, hence treat it as `0`. That's why (3) `null >= 0` is true and (1) `null > 0` is false.
|
||||
|
||||
On the other hand, the equality check `==` for `undefined` and `null` works by the rule, without any conversions. They equal each other and don't equal anything else. That's why (2) `null == 0` is false.
|
||||
On the other hand, the equality check `==` for `undefined` and `null` is defined such that, without any conversions, they equal each other and don't equal anything else. That's why (2) `null == 0` is false.
|
||||
|
||||
### An incomparable undefined
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ Any subtle features of the code? Where they are used?
|
|||
|
||||
## Summary
|
||||
|
||||
An important sign of a good developer is comments: their presence and even their absense.
|
||||
An important sign of a good developer is comments: their presence and even their absence.
|
||||
|
||||
Good comments allow us to maintain the code well, come back to it after a delay and use it more effectively.
|
||||
|
||||
|
|
|
@ -417,7 +417,7 @@ alert(arr); // *!*1, 2, 15*/!*
|
|||
````
|
||||
|
||||
````smart header="Arrow functions for the best"
|
||||
Remember [arrow functions](info:function-expression#arrow-functions)? We can use them here for neater sorting:
|
||||
Remember [arrow functions](info:function-expressions-arrows#arrow-functions)? We can use them here for neater sorting:
|
||||
|
||||
```js
|
||||
arr.sort( (a, b) => a - b );
|
||||
|
|
|
@ -175,7 +175,7 @@ The execution flow of the code above:
|
|||
|
||||
1. The global Lexical Environment has `name: "John"`.
|
||||
2. At the line `(*)` the global variable is changed, now it has `name: "Pete"`.
|
||||
3. When the function `say()`, is executed and takes `name` from outside. Here that's from the global Lexical Environment where it's already `"Pete"`.
|
||||
3. When the function `sayHi()`, is executed and takes `name` from outside. Here that's from the global Lexical Environment where it's already `"Pete"`.
|
||||
|
||||
|
||||
```smart header="One call -- one Lexical Environment"
|
||||
|
|
|
@ -319,7 +319,7 @@ We do a part of the job `(*)`:
|
|||
2. Second run: `i=1000001..2000000`.
|
||||
3. ...and so on, the `while` checks if `i` is evenly divided by `1000000`.
|
||||
|
||||
Then the next call is scheduled in `(*)` if we're not done yet.
|
||||
Then the next call is scheduled in `(**)` if we're not done yet.
|
||||
|
||||
Pauses between `count` executions provide just enough "breath" for the JavaScript engine to do something else, to react to other user actions.
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ For instance:
|
|||
<img id="img" src="https://en.js.cx/clipart/train.gif?speed=1&cache=0">
|
||||
```
|
||||
|
||||
In the example the `DOMContentLoaded` handler runs when the document is loaded, not waits for the page load. So `alert` shows zero sizes.
|
||||
In the example the `DOMContentLoaded` handler runs when the document is loaded and does not wait for the image to load. So `alert` shows zero sizes.
|
||||
|
||||
At the first sight `DOMContentLoaded` event is very simple. The DOM tree is ready -- here's the event. But there are few peculiarities.
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ Here's the full example with all details:
|
|||
|
||||
[codetabs height=380 src="mouseenter-mouseleave-delegation-2"]
|
||||
|
||||
Try to move the cursor in and out of table cells and inside them. Fast or slow -- doesn't better. Only `<td>` as a whole is highlighted unlike the example before.
|
||||
Try to move the cursor in and out of table cells and inside them. Fast or slow -- doesn't matter. Only `<td>` as a whole is highlighted unlike the example before.
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -8,12 +8,12 @@ The solution, step by step:
|
|||
|
||||
<script>
|
||||
// 1)
|
||||
let selectedOption = genres.options[select.selectedIndex];
|
||||
let selectedOption = genres.options[genres.selectedIndex];
|
||||
alert( selectedOption.value );
|
||||
|
||||
// 2)
|
||||
let newOption = new Option("classic", "Classic");
|
||||
select.append(newOption);
|
||||
let newOption = new Option("Classic", "classic");
|
||||
genres.append(newOption);
|
||||
|
||||
// 3)
|
||||
newOption.selected = true;
|
||||
|
|
|
@ -123,7 +123,7 @@ The properties `state` and `result` of the Promise object are internal. We can't
|
|||
|
||||
## Consumers: "then" and "catch"
|
||||
|
||||
A Promise object serves as a link between the executor (the "producing code" or "singer) and the consuming functions (the "fans"), which will receive the result or error. Consuming functions can be registered (subscribed) using the methods `.then` and `.catch`.
|
||||
A Promise object serves as a link between the executor (the "producing code" or "singer") and the consuming functions (the "fans"), which will receive the result or error. Consuming functions can be registered (subscribed) using the methods `.then` and `.catch`.
|
||||
|
||||
The syntax of `.then` is:
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Async/await
|
||||
|
||||
There's a special syntax to work with promises in a more comfort fashion, called "async/await". It's surprisingly easy to understand and use.
|
||||
There's a special syntax to work with promises in a more comfortable fashion, called "async/await". It's surprisingly easy to understand and use.
|
||||
|
||||
## Async functions
|
||||
|
||||
|
|
|
@ -10,12 +10,11 @@ This repository hosts the content of the Modern JavaScript Tutorial, published a
|
|||
|----------|--------|-------------------|-----------------|-----------|
|
||||
| Chinese | https://github.com/xitu/javascript-tutorial-zh | @leviding |  | - |
|
||||
| Danish | https://github.com/ockley/javascript-tutorial-da | @ockey |  | - |
|
||||
| French | https://github.com/SugoiNelson/javascript-tutorial-fr | @SugoiNelson |  | - |
|
||||
| German | https://github.com/MartinEls/javascript-tutorial-de | @MartilEls |  | - |
|
||||
| Japanese | https://github.com/KenjiI/javascript-tutorial-ja | @KenjiI |  | - |
|
||||
| Russian | https://github.com/iliakan/javascript-tutorial-ru | @iliakan | | https://learn.javascript.ru |
|
||||
| Persian | https://github.com/Goudarz/javascript-tutorial-fa | @Goudarz |  | - |
|
||||
| Russian | https://github.com/iliakan/javascript-tutorial-ru | @iliakan | | https://learn.javascript.ru |
|
||||
| Turkish | https://github.com/sahinyanlik/javascript-tutorial-tr | @sahinyanlik |  | - |
|
||||
| Uzbek | https://github.com/aruzikulov/javascript-tutorial-uz | @aruzikulov |  | - |
|
||||
|
||||
If you'd like to translate it into your language, please clone the repository, change its name to `javascript-tutorial-...` (by the language) and [create an issue](https://github.com/iliakan/javascript-tutoria-en/issues/new) for me to add you to the list.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue