Strings 4/5
Strings are Immutable:
Strings, in JavaScript, are immutable which means that their values cannot be changed once declared.
Letβs try to understand this with an example.
1234let stringVariable = 'JavaScript'; // changing the value of first character. stringVariable[0] = 'A'; console.log(stringVariable[0]);
The value did not change.
To do so, the usual practice is to create a new string variable with the value that we want to change and attach the parts of the older string to it. In this way, we can change the string,
1234let str = 'Gi'; // replacing the string G with H str = 'H' + str[1]; console.log(str);
Swipe to start coding
A variable name order
with the assigned value of go
has been given to you. Your task is to change the value go
to to
and display it.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 2
Strings 4/5
Swipe to show menu
Strings are Immutable:
Strings, in JavaScript, are immutable which means that their values cannot be changed once declared.
Letβs try to understand this with an example.
1234let stringVariable = 'JavaScript'; // changing the value of first character. stringVariable[0] = 'A'; console.log(stringVariable[0]);
The value did not change.
To do so, the usual practice is to create a new string variable with the value that we want to change and attach the parts of the older string to it. In this way, we can change the string,
1234let str = 'Gi'; // replacing the string G with H str = 'H' + str[1]; console.log(str);
Swipe to start coding
A variable name order
with the assigned value of go
has been given to you. Your task is to change the value go
to to
and display it.
Solution
Thanks for your feedback!
Awesome!
Completion rate improved to 2single