Basic JavaScript: Understand String Immutability

Hello, I typed this code but it doesn’t run correctly .
// Setup
var myStr = “Jello World”;

// Only change code below this line
myStr[0] = “H”; // Fix Me
myStr = “Hello World”;

1 Like

As the challenge explains, you cannot alter the value of a string by accessing one of this letters.

So this line needs to be fixed.

myStr[0] = “H”; // Fix Me

If you leave it there as it is, the program will try to run it resulting in the following error:

Cannot assign to read only property '0' of string 'Jello World'

Blocking your program from executing so the next line myStr = “Hello World”; won’t be evaluated.

Hello,could you type the answer for me please;

That wouldn’t be helpful, you may clear the challenge, but won’t understand the issue; thus not learning much.

All you have to understand is that this:

myStr[0] = “H”;

is something you cannot do in JS. So if you leave it there for your program to be seen, it will cause errors.

thanks brother

i think this is the most logical question i have seen so far.


Hi, I struggled with this lesson myself. Here’s the instructional video that used to go with the lesson:

Thanks to help, man!