Basic JavaScript: Understand String Immutability

Basic JavaScript: Understand String Immutability
0

#1

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”;


#2

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.


#3

Hello,could you type the answer for me please;


#4

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.


#5

thanks brother
:kissing_heart::kissing_heart::kissing_heart:


#6

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


#7

Hi, I struggled with this lesson myself. Here’s the instructional video that used to go with the lesson: https://www.youtube.com/watch?v=d1UcatFGn00.