GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Data types > Methods of primitives (updated from origin) by stevermeister · Pull Request #11 · javascript-tutorial/uk.javascript.info

Data types > Methods of primitives (updated from origin) #11

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.

Sign up for GitHub

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

Merged
tarasyyyk merged 5 commits into javascript-tutorial:master from stevermeister:translation
May 9, 2019

Uh oh!

There was an error while loading. Please reload this page.

Merged

Data types > Methods of primitives (updated from origin) #11

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
5 commits
Select commit Hold shift + click to select a range
bed0b32
sync with origin
stevermeister May 9, 2019
347ac89
sync with origin
stevermeister May 9, 2019
3659b18
cleanup merge conflicts
stevermeister May 9, 2019
96d6bd3
add 'use strict' condition to solution
tarasyyyk May 9, 2019
8e01b82
corrections from English version
tarasyyyk May 9, 2019
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

21 changes: 8 additions & 13 deletions 21 1-js/05-data-types/01-primitives-methods/1-string-new-property/solution.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,18 @@ str.test = 5; // (*)
alert(str.test);
```

Ви можете отримати два результати:
1. `undefined`
2. помилку.
В залежності від того, втановлений у вас `use strict` чи ні, результати будуть наступними:
1. `undefined` (без строгого режиму)
2. Помилка (строгий режим)

Чому? Давайте повторимо те, що відбувається в рядку `(*)`:
Чому? Давайте повторимо те, що відбувається в рядку, який позначено `(*)`:

1. Коли ми намагаємося отримати доступ до `str`, створюється "об'єкт обгортка".
2. Операція з властивістю здійснюється в ній. Отже, об'єкт отримує властивість `test`.
3. Операція закінчується, і "об'єкт обгортка" зникає.

Отже, на останньому рядку `str` не має властивості. Для кожної операції створюється новий об'єкт обгортка.

Деякі браузери можуть вирішити додатково обмежити програміста і взагалі заборонити присвоювати властивості примітивам. Тому на практиці ми можемо бачити помилки в рядку `(*)`. Але це трохи відрізняється від специфікації.
2. В строгому режимі, спроба запису викличе помилку.
3. В іншому випадку операція здійсниться і об'єкт отримає властивість `test`, але після цього "об'єкт обгортка" зникне.

Отже, якщо код виконується не в строгому режимі, на останньому рядку `str` не матиме властивості `test`.

**Цей приклад чітко показує, що примітиви не є об'єктами.**

Вони просто не можуть зберігати дані.

Всі операції з властивостями/методами виконуються за допомогою тимчасових об'єктів.
Вони не можуть зберігати додаткові данні.
12 changes: 6 additions & 6 deletions 12 1-js/05-data-types/01-primitives-methods/article.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ JavaScript дозволяє працювати з примітивами (ряд
Об'єкт

- можна зберігати декілька значень як властивості.
- може бути створений за допомогою `{}`, наприклад: `{name: "John", age: 30}`. В JavaScript існують й інші об'єкти; функції - це теж об'єкти.
- може бути створений за допомогою `{}`, наприклад: `{name: "John", age: 30}`. В JavaScript існують й інші об'єкти: функції - це теж об'єкти.

Одна з цікавих речей щодо об'єктів полягає в тому, що ми можемо зберігати функцію як одну з його властивостей.

Expand Down Expand Up @@ -48,7 +48,7 @@ john.sayHi(); // Привіт друже!

1. Примітиви залишаються примітивами. Лише значення, як хотіли.
2. JavaScript дозволяє отримати доступ до методів та властивостей рядків, чисел, булеанів та символів.
3. Коли це трапляється, створюється спеціальний "об'єкт обгортка" з додатковою функціональністю, та потім він знищується.
3. Для цього створюється спеціальний "об'єкт обгортка" з додатковою функціональністю, та потім він знищується.

Для кожного примітиву створюється своя "обгортка": `String`, `Number`, `Boolean` та `Symbol`. Отже, вони містять різні набори методів.

Expand Down Expand Up @@ -91,18 +91,18 @@ alert( n.toFixed(2) ); // 1.23
Наприклад:

```js run
alert( typeof 1 ); // "number"
alert( typeof 0 ); // "number"

alert( typeof new Number(1) ); // "object"!
alert( typeof new Number(0) ); // "object"!
```

та завдяки тому що `zero` об'єкт, ми побачимо алерт:
Об'єкти завжди повертають `true` в `if`, отже ми побачимо алерт:

```js run
let zero = new Number(0);

if (zero) { // zero є true, тому що це об'єкт
alert( "zero є true?!?" );
alert( "zero є true!?!" );
}
```

Expand Down
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.