String Immutability. Why am I doing wrong here?

Tell us what’s happening:

Your code so far

// Setup
var myStr = "Jello World";

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36.

Challenge: Understand String Immutability

Link to the challenge:

this will give the error, for the immutability. this lesson is teaching that this line is wrong and can’t work

1 Like

You can’t change individual characters in a string. That’s why they’re immutable. Removing the last line of your code should fix it.

1 Like

Oh right! I got it now, thanks!

I get it now, Thank you so much!

In javascript Strings are immutable i.e. individual characters cannot be changed. But str[1] = 'o' does work in languages like C/C++ because Strings are mutable, in fact in C there are no String types, String is an array of characters.