* feat(curriculum): Add Basic JS Scrimba links * Fix: Add missing video url. * fix: update videoUrl
1.8 KiB
1.8 KiB
id, title, challengeType, videoUrl
id | title | challengeType | videoUrl |
---|---|---|---|
56533eb9ac21ba0edf2244ba | Understand String Immutability | 1 | https://scrimba.com/c/cWPVaUR |
Description
String
values are immutable, which means that they cannot be altered once created.
For example, the following code:
var myStr = "Bob";cannot change the value of
myStr[0] = "J";
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:
var myStr = "Bob";
myStr = "Job";
Instructions
myStr
so it contains the string value of Hello World
using the approach shown in the example above.
Tests
tests:
- text: <code>myStr</code> should have a value of <code>Hello World</code>
testString: assert(myStr === "Hello World", '<code>myStr</code> should have a value of <code>Hello World</code>');
- text: Do not change the code above the line
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
(function(v){return "myStr = " + v;})(myStr);
Solution
var myStr = "Jello World";
myStr = "Hello World";