Skip to content

Commit 599978e

Browse files
committed
sync main
1 parent 539db1f commit 599978e

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

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

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,20 @@ We'll see more about working with numbers in the chapter <info:number>.
6868
6969
## BigInt [#bigint-type]
7070
71-
In JavaScript, the "number" type cannot represent integer values larger than <code>(2<sup>53</sup>-1)</code> (that's `9007199254740991`), or less than <code>-(2<sup>53</sup>-1)</code> for negatives. It's a technical limitation caused by their internal representation.
71+
In JavaScript, the "number" type cannot safely represent integer values larger than <code>(2<sup>53</sup>-1)</code> (that's `9007199254740991`), or less than <code>-(2<sup>53</sup>-1)</code> for negatives.
7272

73-
For most purposes that's quite enough, but sometimes we need really big numbers, e.g. for cryptography or microsecond-precision timestamps.
73+
To be really precise, the "number" type can store larger integers (up to <code>1.7976931348623157 * 10<sup>308</sup></code>), but outside of the safe integer range <code>±(2<sup>53</sup>-1)</code> there'll be a precision error, because not all digits fit into the fixed 64-bit storage. So an "approximate" value may be stored.
74+
75+
For example, these two numbers (right above the safe range) are the same:
76+
77+
```js
78+
console.log(9007199254740991 + 1); // 9007199254740992
79+
console.log(9007199254740991 + 2); // 9007199254740992
80+
```
81+
82+
So to say, all odd integers greater than <code>(2<sup>53</sup>-1)</code> can't be stored at all in the "number" type.
83+
84+
For most purposes <code>±(2<sup>53</sup>-1)</code> range is quite enough, but sometimes we need the entire range of really big integers, e.g. for cryptography or microsecond-precision timestamps.
7485

7586
`BigInt` type was recently added to the language to represent integers of arbitrary length.
7687

@@ -213,7 +224,7 @@ The `symbol` type is used to create unique identifiers for objects. We have to m
213224

214225
## The typeof operator [#type-typeof]
215226

216-
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 do a quick check.
227+
The `typeof` operator returns the type of the operand. It's useful when we want to process values of different types differently or just want to do a quick check.
217228

218229
A call to `typeof x` returns a string with the type name:
219230

@@ -263,14 +274,16 @@ Some people prefer `typeof(x)`, although the `typeof x` syntax is much more comm
263274
264275
There are 8 basic data types in JavaScript.
265276
266-
- `number` for numbers of any kind: integer or floating-point, integers are limited by <code>±(2<sup>53</sup>-1)</code>.
267-
- `bigint` is for integer numbers of arbitrary length.
268-
- `string` for strings. A string may have zero or more characters, there's no separate single-character type.
269-
- `boolean` for `true`/`false`.
270-
- `null` for unknown values -- a standalone type that has a single value `null`.
271-
- `undefined` for unassigned values -- a standalone type that has a single value `undefined`.
272-
- `object` for more complex data structures.
273-
- `symbol` for unique identifiers.
277+
- Seven primitive data types:
278+
- `number` for numbers of any kind: integer or floating-point, integers are limited by <code>±(2<sup>53</sup>-1)</code>.
279+
- `bigint` for integer numbers of arbitrary length.
280+
- `string` for strings. A string may have zero or more characters, there's no separate single-character type.
281+
- `boolean` for `true`/`false`.
282+
- `null` for unknown values -- a standalone type that has a single value `null`.
283+
- `undefined` for unassigned values -- a standalone type that has a single value `undefined`.
284+
- `symbol` for unique identifiers.
285+
- And one non-primitive data type:
286+
- `object` for more complex data structures.
274287
275288
The `typeof` operator allows us to see which type is stored in a variable.
276289

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ The result of `a % b` is the [remainder](https://en.wikipedia.org/wiki/Remainder
5050
For instance:
5151

5252
```js run
53-
alert( 5 % 2 ); // 1, a remainder of 5 divided by 2
54-
alert( 8 % 3 ); // 2, a remainder of 8 divided by 3
53+
alert( 5 % 2 ); // 1, the remainder of 5 divided by 2
54+
alert( 8 % 3 ); // 2, the remainder of 8 divided by 3
55+
alert( 8 % 4 ); // 0, the remainder of 8 divided by 4
5556
```
5657

5758
### Exponentiation **
@@ -68,7 +69,7 @@ alert( 2 ** 3 ); // 2³ = 8
6869
alert( 2 ** 4 ); // 2⁴ = 16
6970
```
7071

71-
Just like in maths, the exponentiation operator is defined for non-integer numbers as well.
72+
Just like in maths, the exponentiation operator is defined for non-integer numbers as well.
7273

7374
For example, a square root is an exponentiation by ½:
7475

@@ -80,7 +81,7 @@ alert( 8 ** (1/3) ); // 2 (power of 1/3 is the same as a cubic root)
8081

8182
## String concatenation with binary +
8283

83-
Let's meet features of JavaScript operators that are beyond school arithmetics.
84+
Let's meet the features of JavaScript operators that are beyond school arithmetics.
8485
8586
Usually, the plus operator `+` sums numbers.
8687
@@ -194,18 +195,18 @@ Here's an extract from the [precedence table](https://developer.mozilla.org/en-U
194195
| Precedence | Name | Sign |
195196
|------------|------|------|
196197
| ... | ... | ... |
197-
| 15 | unary plus | `+` |
198-
| 15 | unary negation | `-` |
199-
| 14 | exponentiation | `**` |
200-
| 13 | multiplication | `*` |
201-
| 13 | division | `/` |
202-
| 12 | addition | `+` |
203-
| 12 | subtraction | `-` |
198+
| 14 | unary plus | `+` |
199+
| 14 | unary negation | `-` |
200+
| 13 | exponentiation | `**` |
201+
| 12 | multiplication | `*` |
202+
| 12 | division | `/` |
203+
| 11 | addition | `+` |
204+
| 11 | subtraction | `-` |
204205
| ... | ... | ... |
205206
| 2 | assignment | `=` |
206207
| ... | ... | ... |
207208

208-
As we can see, the "unary plus" has a priority of `15` which is higher than the `12` of "addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition.
209+
As we can see, the "unary plus" has a priority of `14` which is higher than the `11` of "addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition.
209210
210211
## Assignment
211212
@@ -303,9 +304,9 @@ Such operators have the same precedence as a normal assignment, so they run afte
303304
```js run
304305
let n = 2;
305306
306-
n *= 3 + 5;
307+
n *= 3 + 5; // right part evaluated first, same as n *= 8
307308
308-
alert( n ); // 16 (right part evaluated first, same as n *= 8)
309+
alert( n ); // 16
309310
```
310311

311312
## Increment/decrement
@@ -437,7 +438,7 @@ The list of operators:
437438
- RIGHT SHIFT ( `>>` )
438439
- ZERO-FILL RIGHT SHIFT ( `>>>` )
439440
440-
These operators are used very rarely, when we need to fiddle with numbers on the very lowest (bitwise) level. We won't need these operators any time soon, as web development has little use of them, but in some special areas, such as cryptography, they are useful. You can read the [Bitwise Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Bitwise) chapter on MDN when a need arises.
441+
These operators are used very rarely, when we need to fiddle with numbers on the very lowest (bitwise) level. We won't need these operators any time soon, as web development has little use of them, but in some special areas, such as cryptography, they are useful. You can read the [Bitwise Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#bitwise_operators) chapter on MDN when a need arises.
441442

442443
## Comma
443444

0 commit comments

Comments
 (0)