Gio-jb
October 24, 2019, 10:47am
1
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:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/understand-string-immutability
ILM
October 24, 2019, 10:57am
2
Gio-jb:
myStr[0] = “H”;
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
Gio-jb
October 24, 2019, 11:02am
4
Oh right! I got it now, thanks!
Gio-jb
October 24, 2019, 11:03am
5
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.