Trying to Understand String Immutability

Tell us what’s happening:
Still plugging away at it, but I am stumped again. I thought that myStr[0] = "H"; would change the first letter of the var myStr = "Jello World"; to var myStr = "Hello World";, but I guess I am still missing something… a little help please?

Your code so far


// Setup
var myStr = "Jello World";

// Only change code below this line

myStr[0] = "H"; 
myStr = "Hello World";

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability

this is still wrong syntax, if you run code with this you get an error and it stops running. you can’t change single characters in a string like you would in an array.

the next line is the way to do it. but it doesn’t pass because of the error caused by the other thing

2 Likes

Hi paulrt. You can’t change string by syntax myStr[0] = “H”. You only replace text.
for example var x = “mi Paulrt” if you want change the value of x --> var x =“Hi Paulrt”

1 Like

That is the point of the challenge, to show you that Strings are immutable.

1 Like

Hence the title. Thank you.