mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-30 12:05:39 -05:00
1.3 KiB
1.3 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
| id | title | challengeType | videoUrl | forumTopicId | dashedName |
|---|---|---|---|---|---|
| 56533eb9ac21ba0edf2244ba | 瞭解字符串的不變性 | 1 | https://scrimba.com/c/cWPVaUR | 18331 | understand-string-immutability |
--description--
在 JavaScript 中,字符串(String)的值是不可變的(immutable),這意味着一旦字符串被創建就不能被改變。
例如,以下代碼將產生錯誤,因爲字符串 Bob 中的字母 B 不能更改爲字母 J:
let myStr = "Bob";
myStr[0] = "J";
請注意,這不意味着無法重新分配 myStr。 更改 myStr 的唯一方法是爲其分配一個新值,如下所示:
let myStr = "Bob";
myStr = "Job";
--instructions--
更正對 myStr 的分配,使用上面示例中的方法包含 Hello World 字符串。
--hints--
myStr 的值應該是字符串 Hello World。
assert(myStr === 'Hello World');
不要修改註釋上面的代碼。
assert(/myStr = "Jello World"/.test(code));
--seed--
--after-user-code--
(function(v){return "myStr = " + v;})(myStr);
--seed-contents--
// Setup
let myStr = "Jello World";
// Only change code below this line
myStr[0] = "H"; // Change this line
// Only change code above this line
--solutions--
let myStr = "Jello World";
myStr = "Hello World";