1.5 KiB
1.5 KiB
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244ba | Understand String Immutability | 1 | https://scrimba.com/c/cWPVaUR | 18331 | understand-string-immutability |
--description--
In JavaScript, String
values are immutable, which means that they cannot be altered once created.
For example, the following code:
let myStr = "Bob";
myStr[0] = "J";
cannot change the value of myStr
to Job
, because the contents of myStr
cannot be altered. Note that this does not mean that myStr
cannot be changed, just that the individual characters of a string literal cannot be changed. The only way to change myStr
would be to assign it with a new string, like this:
let myStr = "Bob";
myStr = "Job";
--instructions--
Correct the assignment to myStr
so it contains the string value of Hello World
using the approach shown in the example above.
--hints--
myStr
should have a value of the string Hello World
.
assert(myStr === 'Hello World');
You should not change the code above the specified comment.
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";