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