Files
freeCodeCamp/curriculum/challenges/ukrainian/02-javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability.md
2023-01-13 09:48:11 -08:00

71 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
id: 56533eb9ac21ba0edf2244ba
title: Незмінність рядка
challengeType: 1
videoUrl: 'https://scrimba.com/c/cWPVaUR'
forumTopicId: 18331
dashedName: understand-string-immutability
---
# --description--
Значення рядка (`String`) у JavaScript є <dfn>незмінним</dfn>, тобто його не можна змінити після створення.
Наприклад, наступний код спричинить помилку, оскільки літеру `B` у рядку `Bob` не можна змінити на літеру `J`:
```js
let myStr = "Bob";
myStr[0] = "J";
```
Зауважте, що це *не* означає, що `myStr` не можна повторно присвоїти. Єдиний спосіб змінити `myStr` присвоїти нове значення:
```js
let myStr = "Bob";
myStr = "Job";
```
# --instructions--
Використовуючи приклад вище, виправте присвоєння `myStr` так, щоб значенням рядка було `Hello World`.
# --hints--
`myStr` повинен мати значення рядка `Hello World`.
```js
assert(myStr === 'Hello World');
```
Не змінюйте код над зазначеним коментарем.
```js
assert(/myStr = "Jello World"/.test(code));
```
# --seed--
## --after-user-code--
```js
(function(v){return "myStr = " + v;})(myStr);
```
## --seed-contents--
```js
// Setup
let myStr = "Jello World";
// Only change code below this line
myStr[0] = "H"; // Change this line
// Only change code above this line
```
# --solutions--
```js
let myStr = "Jello World";
myStr = "Hello World";
```