--- id: 56533eb9ac21ba0edf2244ba title: Understand String Immutability challengeType: 1 videoUrl: '' localeTitle: 理解字符串不变性 --- ## Description
在JavaScript中, String值是不可变的 ,这意味着一旦创建它们就不能被更改。例如,以下代码:
var myStr =“Bob”;
myStr [0] =“J”;
无法将myStr的值更改为“Job”,因为myStr的内容无法更改。请注意,这并不意味着myStr不能改变的,只是一个字符串的单个字符不能改变。更改myStr的唯一方法是为其分配一个新字符串,如下所示:
var myStr =“Bob”;
myStr =“工作”;
## Instructions
更正myStr的赋值,使其包含Hello World的字符串值,使用上面示例中显示的方法。
## Tests
```yml tests: - text: myStr应该具有Hello World的值 testString: 'assert(myStr === "Hello World", "myStr should have a value of Hello World");' - text: 不要更改行上方的代码 testString: 'assert(/myStr = "Jello World"/.test(code), "Do not change the code above the line");' ```
## Challenge Seed
```js // Setup var myStr = "Jello World"; // Only change code below this line myStr[0] = "H"; // Fix Me ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```