This commit is contained in:
Ilya Kantor 2016-11-28 21:35:42 +03:00
parent 83b93e5992
commit 9ad9063d00
742 changed files with 884 additions and 779 deletions

View file

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 87 KiB

After

Width:  |  Height:  |  Size: 87 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 74 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 105 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 285 KiB

After

Width:  |  Height:  |  Size: 285 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 83 KiB

Before After
Before After

View file

@ -157,6 +157,4 @@ Please, don't hesitate to comment your code.
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.
Further in the tutorial we'll devote a special chapter to code style, also explaining how to write better comments.
[todo is there such a chapter?]
Further in the tutorial there will be a chapter <info:coding-style> that also explains how to write better comments.

View file

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Before After
Before After

View file

@ -175,10 +175,7 @@ All other types are called "primitive", because their values can contain only a
The `symbol` type is used to create unique identifiers for objects. We have to mention it here for completeness, but we'd better study them after covering objects.
[todo when ? chapter?]
## The typeof operator [#type-typeof]
[todo we need typeof in types]
The `typeof` operator returns the type of the argument. It's useful when we want to process values of different types differently, or just want to make a quick check.

View file

@ -9,11 +9,9 @@ There are also cases when we need to explicitly convert a value to put things ri
[cut]
```smart header="Not covering objects yet"
In this chapter we don't cover objects yet. Here we study primitives first, and then we'll add objects in the chapter [todo].
In this chapter we don't cover objects yet. Here we study primitives first, and then we'll see what happens with objects in the chapter <info:object-toprimitive>.
```
[todo where we cover them? link?]
## ToString
The string conversion happens when we need a string form of a value.
@ -141,30 +139,27 @@ alert( Boolean(" ") ); // also true (any non-empty string is true)
There exist three most widely used type conversions: to string, to number and to boolean.
`ToString`
: Happens when we output something, can be performed with `String(value)`. The conversion to string is usually obvious for primitive values.
**`ToString`** -- occurs when we output something, can be performed with `String(value)`. The conversion to string is usually obvious for primitive values.
`ToNumber`
: Happens in math operations, can be performed with `Number(value)`.
**`ToNumber`** -- occurs in math operations, can be performed with `Number(value)`.
The conversion follows the rules:
The conversion follows the rules:
| Value | Becomes... |
|-------|-------------|
|`undefined`|`NaN`|
|`null`|`0`|
|<code>true&nbsp;/&nbsp;false</code> | `1 / 0` |
| `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string is `0`. An error gives `NaN`. |
| Value | Becomes... |
|-------|-------------|
|`undefined`|`NaN`|
|`null`|`0`|
|<code>true&nbsp;/&nbsp;false</code> | `1 / 0` |
| `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. |
ToBoolean
: Happens in logical operations, or can be performed with `Boolean(value)`.
**`ToBoolean`** -- occurs in logical operations, or can be performed with `Boolean(value)`.
Follows the rules:
Follows the rules:
| Value | Becomes... |
|-------|-------------|
|`0`, `null`, `undefined`, `NaN`, `""` |`false`|
|any other value| `true` |
| Value | Becomes... |
|-------|-------------|
|`0`, `null`, `undefined`, `NaN`, `""` |`false`|
|any other value| `true` |
Most of these rules are easy to understand and memorize. The notable exceptions where people usually make mistakes are:
@ -172,6 +167,4 @@ Most of these rules are easy to understand and memorize. The notable exceptions
- `undefined` is `NaN` as a number.
- `"0"` is true as a boolean.
Objects are not covered here, we'll return to them in the special chapter, devoted exclusively to objects.
[todo link?]
Objects are not covered here, we'll return to them later in the chapter <info:object-toprimitive>, devoted exclusively to objects, after we learn more basic things about Javascript.

View file

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 54 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 92 KiB

Before After
Before After

Some files were not shown because too many files have changed in this diff Show more