Repository navigation
Добавляет 2 задания #448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Добавляет 2 задания #448
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| ```js no-beautify | ||
| [] + [] === "" | ||
| Плюс говорит о строковой операции, а для строковых операций вызывается toString, который переводит массив в пустую строку | ||
|
|
||
| [] + {} === "[object Object]" | ||
| тот же принцип, что и в первом примере — плюс переводит объекты в строку, поэтому на обоих операторах вызывается toString | ||
|
|
||
| {} + [] === 0 | ||
| пустые фигурные скобки трактуются как пустой блок кода, а не как объект, поэтому их можно отбросить. Остается +[]: приведение через унарный плюс массива в число. Пустой массив приводится в число как 0 | ||
|
|
||
| {} + {} === "[object Object][object Object]" | ||
| одни браузеры считают это сложением двух объектов, в то время как другие — опускают пустой блок кода, оставляя объект, переведенный в число унарным плюсом, что, логично, дает NaN | ||
|
dobernike marked this conversation as resolved.
Outdated
|
||
|
|
||
| Array(3).join("wat" - 1) === "NaNNaN" | ||
| join возвращает строку из элементов массива с разделителем, переданным параметром. "wat" - 1 даст NaN, который переводится в строку как NaN | ||
|
|
||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| importance: 5 | ||
|
|
||
| --- | ||
|
|
||
| # WAT | ||
|
|
||
| Если вы уже знаете что такое массив и объект, попробуйте ответить, что выведут примеры из одноименного доклада. | ||
|
dobernike marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```js no-beautify | ||
| [] + [] | ||
| [] + {} | ||
| {} + [] | ||
| {} + {} | ||
| Array(3).join("wat" - 1) | ||
| ``` | ||
|
|
||
| Когда закончите – сверьтесь с решением. | ||
22 changes: 22 additions & 0 deletions
22
1-js/02-first-steps/06-type-conversions/3-primitive-conversions-quizes/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| ```js no-beautify | ||
| '5' - 3 === 2 // (1) | ||
| '5' + 3 === '53' // (2) | ||
| '5' - '4' === 1 // (3) | ||
| '5' + + '5' === '55' // (4) | ||
| 'foo' + + 'foo' === 'fooNaN' // (5) | ||
| '5' + - '2' === '5-2' // (6) | ||
| '5' + - + - - + - - + + - + - + - + - - - '-2' === '52' // (7) | ||
| let x = 3; | ||
| '5' + x - x === 50 // (8) | ||
| '5' - x + x === 5 // (9) | ||
| ``` | ||
|
|
||
| 1. Оператор `-` является числовым, строка `'5'` переводится в число и получается `5 - 3`. | ||
| 2. Оператор `+` используется для строкового и математического, больший приоритет у строкового из-за этого `3` становится строкой и получается `'5' + '3'`. | ||
|
dobernike marked this conversation as resolved.
Outdated
|
||
| 3. Оператор `-` является числовым, строки преобразуются в числа и получается `5 - 4`. | ||
|
dobernike marked this conversation as resolved.
Outdated
|
||
| 4. Приоритет у данных операторов одинаковый, из-за этого происходит следующие: берется первая часть `'5' +` и ожидается вычисление `+ '5'` (перевод строки в число) и выходит `'5' + 5` | ||
|
dobernike marked this conversation as resolved.
Outdated
|
||
| 5. Также как и в предыдущем выражении, за одним но, вторая часть `+ 'foo'` пытается приобразовать `'foo'` в число и выходит `NaN`. | ||
|
dobernike marked this conversation as resolved.
Outdated
|
||
| 6. Также как и в предыдущем выражении, но вторая часть `- '2'` преобразовывается в число `-2` и получается `'5' + -2`. | ||
|
dobernike marked this conversation as resolved.
Outdated
|
||
| 7. Сначала `'5' +` происходит строковое сложение, то есть в итоге `'5'` в начале так и останется, давайте посмотрим вторую часть: как можно видеть используются множетсва унарных операторов `+` и `-`, унарный `+` просто приводит строку в число, а унарный `-` приводит строку в число и меняет знак на противоположный, следовательно унарный `+` в данном выражении можно не считать, а просто посчитать количество `-`, выходит 11 знаков `-` что является нечетным числом и в конечном итоге дает 1 `-` (если четное число, то `+`), далее делаем операцию `- -2` и получаем в итоге `'5' + 2`. | ||
|
dobernike marked this conversation as resolved.
Outdated
|
||
| 8. `'5' + 3 = '53'` строковое сложение, далее `'53' - 3`. | ||
| 9. `'5' - 3 = 2` математическое вычитание, далее `2 + 3`. | ||
22 changes: 22 additions & 0 deletions
22
1-js/02-first-steps/06-type-conversions/3-primitive-conversions-quizes/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| importance: 5 | ||
|
|
||
| --- | ||
|
|
||
| # Продвинутое преобразование типов | ||
|
|
||
| Попробуйте ответить, что выведут примеры из популярной картинки. | ||
|
dobernike marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```js no-beautify | ||
| '5' - 3 | ||
| '5' + 3 | ||
| '5' - '4' | ||
| '5' + + '5' | ||
| 'foo' + + 'foo' | ||
| '5' + - '2' | ||
| '5' + - + - - + - - + + - + - + - + - - - '-2' | ||
| let x = 3; | ||
| '5' + x - x | ||
| '5' - x + x | ||
| ``` | ||
|
|
||
| Когда закончите – сверьтесь с решением. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.