Skip to content

Commit 728c1d2

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-8d04d0d2
2 parents 4c5e5dc + 8d04d0d commit 728c1d2

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,7 @@ The `symbol` type is used to create unique identifiers for objects. We have to m
213213

214214
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.
215215

216-
It supports two forms of syntax:
217-
218-
1. As an operator: `typeof x`.
219-
2. As a function: `typeof(x)`.
220-
221-
In other words, it works with parentheses or without them. The result is the same.
222-
223-
The call to `typeof x` returns a string with the type name:
216+
A call to `typeof x` returns a string with the type name:
224217

225218
```js
226219
typeof undefined // "undefined"
@@ -251,9 +244,19 @@ typeof alert // "function" (3)
251244
The last three lines may need additional explanation:
252245

253246
1. `Math` is a built-in object that provides mathematical operations. We will learn it in the chapter <info:number>. Here, it serves just as an example of an object.
254-
2. The result of `typeof null` is `"object"`. That's an officially recognized error in `typeof` behavior, coming from the early days of JavaScript and kept for compatibility. Definitely, `null` is not an object. It is a special value with a separate type of its own.
247+
2. The result of `typeof null` is `"object"`. That's an officially recognized error in `typeof`, coming from very early days of JavaScript and kept for compatibility. Definitely, `null` is not an object. It is a special value with a separate type of its own. The behavior of `typeof` is wrong here.
255248
3. The result of `typeof alert` is `"function"`, because `alert` is a function. We'll study functions in the next chapters where we'll also see that there's no special "function" type in JavaScript. Functions belong to the object type. But `typeof` treats them differently, returning `"function"`. That also comes from the early days of JavaScript. Technically, such behavior isn't correct, but can be convenient in practice.
256249

250+
```smart header="The `typeof(x)` syntax"
251+
You may also come across another syntax: `typeof(x)`. It's the same as `typeof x`.
252+
253+
To put it clear: `typeof` is an operator, not a function. The parentheses here aren't a part of `typeof`. It's the kind of parentheses used for mathematical grouping.
254+
255+
Usually, such parentheses contain a mathematical expression, such as `(2 + 2)`, but here they contain only one argument `(x)`. Syntactically, they allow to avoid a space between the `typeof` operator and its argument, and some people like it.
256+
257+
Some people prefer `typeof(x)`, although the `typeof x` syntax is much more common.
258+
```
259+
257260
## Summary
258261
259262
There are 8 basic data types in JavaScript.
@@ -269,7 +272,7 @@ There are 8 basic data types in JavaScript.
269272
270273
The `typeof` operator allows us to see which type is stored in a variable.
271274
272-
- Two forms: `typeof x` or `typeof(x)`.
275+
- Usually used as `typeof x`, but `typeof(x)` is also possible.
273276
- Returns a string with the name of the type, like `"string"`.
274277
- For `null` returns `"object"` -- this is an error in the language, it's not actually an object.
275278

1-js/04-object-basics/04-object-methods/8-chain-calls/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let ladder = {
2323
}
2424
};
2525

26-
ladder.up().up().down().up().down().showStep(); // 1
26+
ladder.up().up().down().showStep().down().showStep(); // shows 1 then 0
2727
```
2828

2929
We also can write a single call per line. For long chains it's more readable:
@@ -33,7 +33,7 @@ ladder
3333
.up()
3434
.up()
3535
.down()
36-
.up()
36+
.showStep() // 1
3737
.down()
38-
.showStep(); // 1
38+
.showStep(); // 0
3939
```

1-js/04-object-basics/04-object-methods/8-chain-calls/task.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ ladder.up();
2828
ladder.up();
2929
ladder.down();
3030
ladder.showStep(); // 1
31+
ladder.down();
32+
ladder.showStep(); // 0
3133
```
3234

3335
Modify the code of `up`, `down` and `showStep` to make the calls chainable, like this:
3436

3537
```js
36-
ladder.up().up().down().showStep(); // 1
38+
ladder.up().up().down().showStep().down().showStep(); // shows 1 then 0
3739
```
3840

3941
Such approach is widely used across JavaScript libraries.

2-ui/3-event-details/6-pointer-events/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ Pointer events allow handling mouse, touch and pen events simultaneously, with a
271271

272272
Pointer events extend mouse events. We can replace `mouse` with `pointer` in event names and expect our code to continue working for mouse, with better support for other device types.
273273

274-
For drag'n'drops and complex touch interactions that the browser may decide to hijack and handle on its own - remember to cancel the default action on events and set `touch-events: none` in CSS for elements that we engage.
274+
For drag'n'drops and complex touch interactions that the browser may decide to hijack and handle on its own - remember to cancel the default action on events and set `touch-action: none` in CSS for elements that we engage.
275275

276276
Additional abilities of pointer events are:
277277

0 commit comments

Comments
 (0)